diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f64ea1e..b4e3efee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,73 @@ ### 💐 同时自动更新 GitHub Pages 同步 Gitee; ### 💐 感谢各位贡献者的支持。 🔥 +## 0.0.55-beta14 +
+ 01. 🌈 添加对中转服务 node-hiprint-transit 的支持 + + [中转服务 node-hiprint-transit](https://github.com/Xavier9896/node-hiprint-transit) + + ```js + import { hiprint } from 'vue-plugin-hiprint' + + hiprint.init({ + host: 'https://printjs.cn:17521', // 此处输入服务启动后的地址 + token: 'vue-plugin-hiprint', // 用于鉴权的token + }); + + // or + + hiwebSocket.setHost("https://printjs.cn:17521", "vue-plugin-hiprint") + + console.log(hiwebSocket.clients, hiwebSocket.printerList) + + // 中转服务专有的 api,可获取所有连接中转服务的客户端 v1.0.7 + hiprint.getClients() + hiwebSocket.getClients() + ``` + 详情转至 [文档说明](./README.md#使用-中转服务-node-hiprint-transit-实现代理) +
+
+ 02. 🌈 新的客户端信息获取 + +原本你可以通过 hiprint.getAddress 或 hiwebSocket.getAddress 获取客户端的 ip、ipv6、mac、dns、all、interface、vboxnext 信息,但是需要你主动调用方法去获取。 + +在 v1.0.7 中我们仍然保留该方式,但移除了用处不大的 dns、interface、vboxnext 类型,同时在连接成功后自动返回客户端 clientInfo 信息 + +```js +// 手动获取方法 +hiprint.getClientInfo() +// or +hiwebSocket.getClientInfo() +``` +```js +console.log(hiwebSocket.clientInfo) + +{ + arch: "x64", + clientUrl: "http://192.168.0.2:17521", + ip: "192.168.0.2", + ipv6: "fe80::13f:eb0f:e426:7c92", + mac: "a1:a2:a3:a4:a5:a6", + machineId: "12c90ff9-b9f4-4178-9099-9dd326b70c2e", + platform: "win32", + printerList: [{ + description: "", + displayName: "Microsoft Print to PDF", + isDefault: true, + name: "Microsoft Print to PDF", + options: {, + "printer-location": "", + "printer-make-and-model": "Microsoft Print To PDF", + "system_driverinfo": "Microsoft Print To PDF;10.0.19041.3570 (WinBuild.160101.0800);Microsoft® Windows® Operating System;10.0.19041.3570" + }, + status: 0 + }, {…}, {…}, {…}, {…}, {…}], + version: "1.0.7", +} +``` +
+ ## 0.0.55-beta8(2023-09-12)
01. 🌈 添加国际化 i18n 支持 diff --git a/README.md b/README.md index d9914eaf..802070e2 100644 --- a/README.md +++ b/README.md @@ -324,6 +324,82 @@ hiprintTemplate.print2({}); - [线上跨域问题,请升级 https! 说明:https://www.cnblogs.com/daysme/p/15493523.html](https://www.cnblogs.com/daysme/p/15493523.html) - [线上跨域问题,请升级 https! 说明:https://www.cnblogs.com/daysme/p/15493523.html](https://www.cnblogs.com/daysme/p/15493523.html) +### URLScheme `hiprint://` +> 安装客户端时请 `以管理员身份运行` ,才能成功添加 URLScheme + +使用:浏览器地址栏输入 `hiprint://` 并回车 + +![URLScheme](./res/URLScheme.png) + +```js +// js +window.open("hiprint://") + +// element-ui +this.$alert(`连接【${hiwebSocket.host}】失败!
请确保目标服务器已 下载 运行 打印服务!`, "客户端未连接", {dangerouslyUseHtmlString: true}) + +// ant-design +this.$error({ + title: "客户端未连接", + content: (h) => ( +
+ 连接【{hiwebSocket.host}】失败! +
+ 请确保目标服务器已 + + 下载 + + 并 + + 运行 + + 打印服务! +
+ ), +}); +``` + +## 使用 [中转服务 node-hiprint-transit](https://github.com/Xavier9896/node-hiprint-transit) 实现代理 + +配套客户端打印一直存在跨域、无法连接局域网其余打印机、跨网段无法连接的问题,所以诞生了这个中转代理服务。在 `electron-hiprint` [v1.0.0.7](https://gitee.com/CcSimple/electron-hiprint/releases) 版本中添加了连接中转服务代理的设置,将会在 `electron-hiprint` 与 `node-hiprint-transit` 间建立通信,`vue-plugin-hiprint` 只需连接中转服务就能获取到所有连接中转服务的打印端信息,并且选择任意打印机进行打印。 + +连接中转服务只需要修改 host, 添加 token + +```js +import { hiprint } from 'vue-plugin-hiprint' + +hiprint.init({ + host: 'https://printjs.cn:17521', // 此处输入服务启动后的地址 + token: 'vue-plugin-hiprint', // 用于鉴权的token +}); + +// or + +hiwebSocket.setHost("https://printjs.cn:17521", "vue-plugin-hiprint") +``` + +具体使用请转至 [node-hiprint-transit](https://github.com/Xavier9896/node-hiprint-transit) + +为此你需要作出这些改变: + +1. 你可以从 `hiwebSocket` 中获取到 `clients`、`printerList` ,里面都将包含 `client` 信息 +2. print2、ippRequest、ippRequest api options 中需要添加 `client` 指定客户端 + + eg: + ```js + var clientId = "AlBaUCNs3AIMFPLZAAAh" + var client = hiwebSocket.clients[clientId] + var printer = hiwebSocket.printerList[0] + + hiprintTemplate.print2(printData, { client: clientId, printer: client.printerList[n].name, title: 'hiprint测试打印' }); + + hiprintTemplate.print2(printData, { client: printer.clientId, printer: printer.name, title: 'hiprint测试打印' }); + ``` + > 如果你不提供 client 中转服务将抛出一个 error + ## 常见问题 > design时怎么修改默认图片? ```vue diff --git a/res/URLScheme.png b/res/URLScheme.png new file mode 100644 index 00000000..33f907f5 Binary files /dev/null and b/res/URLScheme.png differ diff --git a/src/demo/custom/index.vue b/src/demo/custom/index.vue index f58fab61..d4d461f1 100644 --- a/src/demo/custom/index.vue +++ b/src/demo/custom/index.vue @@ -273,7 +273,27 @@ export default { hiprintTemplate.print2(printData, {printer: '', title: 'hiprint测试打印'}); return } - this.$message.error('客户端未连接,无法直接打印') + this.$error({ + title: "客户端未连接", + content: (h) => ( +
+ 连接【{hiwebSocket.host}】失败! +
+ 请确保目标服务器已 + + 下载 + + 并 + + 运行 + + 打印服务! +
+ ), + }); }, save() { let {mode} = this diff --git a/src/demo/design/index.vue b/src/demo/design/index.vue index ef99377d..f872f203 100644 --- a/src/demo/design/index.vue +++ b/src/demo/design/index.vue @@ -98,7 +98,7 @@ - @@ -107,7 +107,7 @@ 导出json模板到 textArea - + @@ -717,7 +717,27 @@ export default { }); return; } - this.$message.error('客户端未连接,无法直接打印') + this.$error({ + title: "客户端未连接", + content: (h) => ( +
+ 连接【{hiwebSocket.host}】失败! +
+ 请确保目标服务器已 + + 下载 + + 并 + + 运行 + + 打印服务! +
+ ), + }); }, print() { if (window.hiwebSocket.opened) { @@ -726,7 +746,27 @@ export default { hiprintTemplate.print2(printData, {printer: '', title: 'hiprint测试打印'}); return } - this.$message.error('客户端未连接,无法直接打印') + this.$error({ + title: "客户端未连接", + content: (h) => ( +
+ 连接【{hiwebSocket.host}】失败! +
+ 请确保目标服务器已 + + 下载 + + 并 + + 运行 + + 打印服务! +
+ ), + }); }, clearPaper() { try { diff --git a/src/demo/panels/index.vue b/src/demo/panels/index.vue index b7a33cf4..a1ffcdd6 100644 --- a/src/demo/panels/index.vue +++ b/src/demo/panels/index.vue @@ -282,7 +282,27 @@ export default { hiprintTemplate.print2(printData, {printer: '', title: 'hiprint测试打印'}); return } - this.$message.error('客户端未连接,无法直接打印') + this.$error({ + title: "客户端未连接", + content: (h) => ( +
+ 连接【{hiwebSocket.host}】失败! +
+ 请确保目标服务器已 + + 下载 + + 并 + + 运行 + + 打印服务! +
+ ), + }); }, save() { let json = hiprintTemplate.getJson(); diff --git a/src/demo/tasks/index.vue b/src/demo/tasks/index.vue index e2ac81e9..3a0e734a 100644 --- a/src/demo/tasks/index.vue +++ b/src/demo/tasks/index.vue @@ -218,7 +218,27 @@ export default { this.tasksPrint() return } - this.$message.error('客户端未连接,无法直接打印') + this.$error({ + title: "客户端未连接", + content: (h) => ( +
+ 连接【{hiwebSocket.host}】失败! +
+ 请确保目标服务器已 + + 下载 + + 并 + + 运行 + + 打印服务! +
+ ), + }); }, // 队列打印 tasksPrint() { diff --git a/src/hiprint/hiprint.bundle.js b/src/hiprint/hiprint.bundle.js index fbeba120..ce4dcd1f 100644 --- a/src/hiprint/hiprint.bundle.js +++ b/src/hiprint/hiprint.bundle.js @@ -7473,6 +7473,13 @@ var hiprint = function (t) { console.log("refreshPrinterList error:" + JSON.stringify(e)); } }, + getClients: function getClients() { + try { + this.socket.emit("getClients"); + } catch (e) { + console.log("getClients error:" + JSON.stringify(e)); + } + }, getAddress: function getAddress(type, ...args) { try { this.socket.emit("address", type, ...args); @@ -7519,6 +7526,12 @@ var hiprint = function (t) { hinnn.event.trigger("printSuccess_" + t.templateId, t); }), _this.socket.on("error", function (t) { hinnn.event.trigger("printError_" + t.templateId, t); + }), _this.socket.on("clients", function(clients) { + t.clients = clients; + hinnn.event.trigger("clients", clients) + }), _this.socket.on("clientInfo", function(clientInfo) { + t.clientInfo = clientInfo + hinnn.event.trigger("clientInfo", clientInfo) }), _this.socket.on("printerList", function (e) { t.printerList = e; hinnn.event.trigger("printerList", e); @@ -10688,6 +10701,18 @@ var hiprint = function (t) { hiwebSocket.refreshPrinterList(); } + function getClients(c) { + p.a.instance.clear("clients"); + p.a.instance.on("clients", c); + hiwebSocket.getClients(); + } + + function getClientInfo(c) { + p.a.instance.clear("clientInfo"); + p.a.instance.on("getClientInfo", c); + hiwebSocket.getClientInfo() + } + function getAddr(type, c, ...args) { p.a.instance.clear("address_" + type); p.a.instance.on("address_" + type, c); @@ -10715,9 +10740,13 @@ var hiprint = function (t) { }), n.d(e, "updateElementType", function () { return uep; }), n.d(e, "hiwebSocket", function () { - return hiwebSocket + return hiwebSocket; }), n.d(e, "refreshPrinterList", function () { return rpl; + }), n.d(e, "getClients", function() { + return getClients; + }), n.d(e, "getClientInfo", function() { + return getClientInfo; }), n.d(e, "getAddress", function () { return getAddr; }), n.d(e, "ippPrint", function () {