Skip to content

Commit

Permalink
Merge pull request #71 from Xavier9896/main
Browse files Browse the repository at this point in the history
add 添加 中转服务 连接说明,添加 clientInfo 接收,添加 URLScheme 使用及文档说明
  • Loading branch information
CcSimple authored Oct 15, 2023
2 parents a0775d9 + dc0abb1 commit 6533056
Show file tree
Hide file tree
Showing 8 changed files with 280 additions and 8 deletions.
67 changes: 67 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,73 @@
### 💐 同时自动更新 GitHub Pages 同步 Gitee;
### 💐 感谢各位贡献者的支持。 🔥

## 0.0.55-beta14
<details>
<summary>01. 🌈 添加对中转服务 node-hiprint-transit 的支持</summary>

[中转服务 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-实现代理)
</details>
<details>
<summary>02. 🌈 新的客户端信息获取</summary>

原本你可以通过 hiprint.getAddresshiwebSocket.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",
}
```
</details>

## 0.0.55-beta8(2023-09-12)
<details>
<summary>01. 🌈 添加国际化 i18n 支持 </summary>
Expand Down
76 changes: 76 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}】失败!<br>请确保目标服务器已<a href="https://gitee.com/CcSimple/electron-hiprint/releases" target="_blank"> 下载 </a> 并 <a href="hiprint://" target="_blank"> 运行 </a> 打印服务!`, "客户端未连接", {dangerouslyUseHtmlString: true})

// ant-design
this.$error({
title: "客户端未连接",
content: (h) => (
<div>
连接【{hiwebSocket.host}】失败!
<br />
请确保目标服务器已
<a
href="https://gitee.com/CcSimple/electron-hiprint/releases"
target="_blank"
>
下载
</a>
<a href="hiprint://" target="_blank">
运行
</a>
打印服务!
</div>
),
});
```

## 使用 [中转服务 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
Expand Down
Binary file added res/URLScheme.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 21 additions & 1 deletion src/demo/custom/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,27 @@ export default {
hiprintTemplate.print2(printData, {printer: '', title: 'hiprint测试打印'});
return
}
this.$message.error('客户端未连接,无法直接打印')
this.$error({
title: "客户端未连接",
content: (h) => (
<div>
连接【{hiwebSocket.host}】失败!
<br />
请确保目标服务器已
<a
href="https://gitee.com/CcSimple/electron-hiprint/releases"
target="_blank"
>
下载
</a>
<a href="hiprint://" target="_blank">
运行
</a>
打印服务!
</div>
),
});
},
save() {
let {mode} = this
Expand Down
48 changes: 44 additions & 4 deletions src/demo/design/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
</a-button>
</a-space>
<a-space style="margin-bottom: 10px">
<a-textarea style="width:30vw" v-model:value="jsonIn" @pressEnter="updateJson"
<a-textarea style="width:30vw" v-model="jsonIn" @pressEnter="updateJson"
placeholder="复制json模板到此后 点击右侧更新"
allow-clear/>
<a-button type="primary" @click="updateJson">
Expand All @@ -107,7 +107,7 @@
<a-button type="primary" @click="exportJson">
导出json模板到 textArea
</a-button>
<a-textarea style="width:30vw" v-model:value="jsonOut" placeholder="点击左侧导出json" allow-clear/>
<a-textarea style="width:30vw" v-model="jsonOut" placeholder="点击左侧导出json" allow-clear/>
</a-space>
<a-space style="margin-bottom: 10px">
<a-button type="primary" @click="getSelectEls">
Expand Down Expand Up @@ -717,7 +717,27 @@ export default {
});
return;
}
this.$message.error('客户端未连接,无法直接打印')
this.$error({
title: "客户端未连接",
content: (h) => (
<div>
连接【{hiwebSocket.host}】失败!
<br />
请确保目标服务器已
<a
href="https://gitee.com/CcSimple/electron-hiprint/releases"
target="_blank"
>
下载
</a>
<a href="hiprint://" target="_blank">
运行
</a>
打印服务!
</div>
),
});
},
print() {
if (window.hiwebSocket.opened) {
Expand All @@ -726,7 +746,27 @@ export default {
hiprintTemplate.print2(printData, {printer: '', title: 'hiprint测试打印'});
return
}
this.$message.error('客户端未连接,无法直接打印')
this.$error({
title: "客户端未连接",
content: (h) => (
<div>
连接【{hiwebSocket.host}】失败!
<br />
请确保目标服务器已
<a
href="https://gitee.com/CcSimple/electron-hiprint/releases"
target="_blank"
>
下载
</a>
<a href="hiprint://" target="_blank">
运行
</a>
打印服务!
</div>
),
});
},
clearPaper() {
try {
Expand Down
22 changes: 21 additions & 1 deletion src/demo/panels/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,27 @@ export default {
hiprintTemplate.print2(printData, {printer: '', title: 'hiprint测试打印'});
return
}
this.$message.error('客户端未连接,无法直接打印')
this.$error({
title: "客户端未连接",
content: (h) => (
<div>
连接【{hiwebSocket.host}】失败!
<br />
请确保目标服务器已
<a
href="https://gitee.com/CcSimple/electron-hiprint/releases"
target="_blank"
>
下载
</a>
<a href="hiprint://" target="_blank">
运行
</a>
打印服务!
</div>
),
});
},
save() {
let json = hiprintTemplate.getJson();
Expand Down
22 changes: 21 additions & 1 deletion src/demo/tasks/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,27 @@ export default {
this.tasksPrint()
return
}
this.$message.error('客户端未连接,无法直接打印')
this.$error({
title: "客户端未连接",
content: (h) => (
<div>
连接【{hiwebSocket.host}】失败!
<br />
请确保目标服务器已
<a
href="https://gitee.com/CcSimple/electron-hiprint/releases"
target="_blank"
>
下载
</a>
<a href="hiprint://" target="_blank">
运行
</a>
打印服务!
</div>
),
});
},
// 队列打印
tasksPrint() {
Expand Down
31 changes: 30 additions & 1 deletion src/hiprint/hiprint.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 () {
Expand Down

0 comments on commit 6533056

Please sign in to comment.