Skip to content

Commit 25506f5

Browse files
committed
新增支持 设置是否自动连接客户端
1 parent 82941b1 commit 25506f5

File tree

8 files changed

+62
-5
lines changed

8 files changed

+62
-5
lines changed

README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
![image](https://badgen.net/packagephobia/install/vue-plugin-hiprint)
1414

1515
# vue-plugin-hiprint <a href="http://hiprint.io/docs/start">hiprint官方文档</a>
16-
> hiprint for vue2.0
16+
> hiprint for vue2.x
1717
1818
## 配套直接打印客户端(win/mac/linux)
19-
### <a href="https://gitee.com/CcSimple/electron-hiprint">gitee</a> <a href="https://gitee.com/CcSimple/electron-hiprint"> github</a>
19+
### <a href="https://gitee.com/CcSimple/electron-hiprint">gitee</a> <a href="https://github.com/CcSimple/electron-hiprint"> github</a>
2020
<div align="center">
2121

2222
![image](./res/tool.jpeg)
@@ -184,6 +184,27 @@ hiprint.setConfig({
184184
}
185185
})
186186
```
187+
> 取消自动socket连接 / socket连接报错问题
188+
```javascript
189+
/**
190+
* 取消自动连接
191+
*/
192+
// 在main.js中设置
193+
import {hiPrintPlugin} from 'vue-plugin-hiprint'
194+
Vue.use(hiPrintPlugin,'$hiprint', false);
195+
// hiPrintPlugin 同时提供了 disAutoConnect 方法
196+
hiPrintPlugin.disAutoConnect();
197+
// 在组件中使用 见: demo/design/index.vue
198+
import {disAutoConnect, hiprint} from 'vue-plugin-hiprint'
199+
disAutoConnect();
200+
// 同时 export了 autoConnect,disAutoConnect 方法
201+
/**
202+
* socket连接报错?
203+
* 由于npm包更新到socket.io 3.x版本,官网提供的客户端,npm包是无法连接的
204+
* 请使用gitee提供的客户端, 同时gitee客户端可传更多的参数, 如是否打印颜色/打印份数/DPI等
205+
* 详情electron见:https://www.electronjs.org/zh/docs/latest/api/web-contents
206+
*/
207+
```
187208

188209
## 交流群
189210
<div align="center">
@@ -199,6 +220,8 @@ hiprint.setConfig({
199220
![image](./res/img.png)
200221

201222
![image](./res/img_1.png)
223+
224+
![image](./res/img_2.png)
202225
</div>
203226

204227
## 状态/调整/优化
@@ -217,6 +240,7 @@ hiprint.setConfig({
217240
- [x] `字段名优化调整` 元素的字段名(field) 支持嵌套(eg: a.b.c.d)
218241
- [x] `新增支持不分页(小票打印)` 可设置不分页 table、longText处理
219242
- [x] `新增支持复制/粘贴` 支持 基本元素的ctrl+c/v(复制/粘贴)
243+
- [x] `新增支持设置是否自动连接客户端` 支持 不自动连接'直接打印'客户端
220244

221245
### 咳咳..
222246
第一次写插件(webpack打包这些都不太了解),不合理的地方欢迎指正<a href="https://github.com/CcSimple/vue-plugin-hiprint/issues">issues</a>。

res/img.png

-38.7 KB
Loading

res/img_2.png

96.8 KB
Loading

res/wechat.png

-693 Bytes
Loading

src/demo/design/index.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@
135135
</template>
136136

137137
<script>
138-
import {hiprint, defaultElementTypeProvider} from '../../index'
138+
import {disAutoConnect, hiprint, defaultElementTypeProvider} from '../../index'
139+
// disAutoConnect();
139140
140141
let hiprintTemplate;
141142
import panel from './panel'

src/hiprint/hiprint.bundle.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8233,6 +8233,8 @@ var hiprint = function (t) {
82338233
return mt;
82348234
}), n.d(e, "setConfig", function () {
82358235
return cig;
8236+
}), n.d(e, "hiwebSocket", function () {
8237+
return hiwebSocket
82368238
}), n.d(e, "PrintElementTypeManager", function () {
82378239
return it;
82388240
}), n.d(e, "PrintElementTypeGroup", function () {
@@ -8246,7 +8248,11 @@ var hiprint = function (t) {
82468248
}), n.d(e, "getHtml", function () {
82478249
return gt;
82488250
}), $(document).ready(function () {
8249-
hiwebSocket.hasIo() && hiwebSocket.start();
8251+
console.log('document ready');
8252+
console.log(window.autoConnect);
8253+
if (hiwebSocket.hasIo() && window.autoConnect){
8254+
hiwebSocket.start();
8255+
}
82508256
});
82518257
}]);
82528258

src/index.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ require('./hiprint/hiprint.config')
1717
function initJquery() {
1818
if (window !== undefined) {
1919
window.jQuery = window.$ = jQuery;
20+
window.autoConnect = true;
2021
}
2122
}
2223

@@ -26,8 +27,30 @@ function initConfig() {
2627

2728
initJquery()
2829

30+
/**
31+
* 自动连接 / 连接
32+
*/
33+
let autoConnect = function() {
34+
console.log('autoConnect');
35+
window.autoConnect = true;
36+
window.hiwebSocket && window.hiwebSocket.hasIo() && window.hiwebSocket.start();
37+
};
38+
39+
/**
40+
* 取消自动连接 / 断开连接
41+
*/
42+
let disAutoConnect = function() {
43+
console.log('disAutoConnect');
44+
window.autoConnect = false;
45+
window.hiwebSocket && window.hiwebSocket.hasIo() && window.hiwebSocket.stop();
46+
};
47+
2948
let hiPrintPlugin = {
30-
install: function (Vue, name = '$hiPrint') {
49+
disAutoConnect,
50+
install: function (Vue, name = '$hiPrint', autoConnect = true) {
51+
if (!autoConnect) {
52+
disAutoConnect();
53+
}
3154
Object.defineProperty(Vue.prototype, name, {value: hiprint});
3255
// Vue.component(HiPrint.name, HiPrint) // printPanel.name 组件的name属性
3356
/**
@@ -66,6 +89,8 @@ let hiPrintPlugin = {
6689
}
6790

6891
export {
92+
autoConnect,
93+
disAutoConnect,
6994
hiprint,
7095
hiPrintPlugin,
7196
defaultElementTypeProvider,

src/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Vue.use(Antd);
77

88
import {hiPrintPlugin} from './index'
99
Vue.use(hiPrintPlugin)
10+
// hiPrintPlugin.disAutoConnect();
1011

1112
import Storage from 'vue-ls'
1213
let options = {

0 commit comments

Comments
 (0)