chenhaozhe
3 天以前 00ed7e51cecfc5e97e88bf2c9838c87362ea396d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import {hiprint, defaultElementTypeProvider} from '../hiprint/hiprint.bundle.js'
// 调用浏览器打印js
import "../hiprint/plugins/jquery.hiwprint.js";
// 默认配置
import "../hiprint/hiprint.config";
// 样式
import "../hiprint/css/hiprint.css"
import "../hiprint/css/print-lock.css"
 
import {version} from '../../package.json'
 
//TODO  socket.io 版本冲突,无法开启,想要使用客户端需要研究
/**
 * 自动连接 / 连接
 * cb: 连接回调, (status, msg) {
 *   // status: true/false
 *   // msg: status == true 时 返回socket.connect回调 e
 * }
 */
let autoConnect = function(cb) {
  console.log('autoConnect');
  window.autoConnect = true;
  window.hiwebSocket && window.hiwebSocket.hasIo() && window.hiwebSocket.start(cb);
};
 
/**
 * 取消自动连接 / 断开连接
 */
let disAutoConnect = function() {
  console.log('disAutoConnect');
  window.autoConnect = false;
  window.hiwebSocket && window.hiwebSocket.hasIo() && window.hiwebSocket.stop();
};
 
let hiPrintPlugin = {
  disAutoConnect,
  install: function (Vue, name = '$hiPrint', autoConnect = true) {
    if (!autoConnect) {
      disAutoConnect();
    }
    let globalVue = Vue.prototype || Vue.config.globalProperties;
    globalVue[name] = hiprint;
    /**
   * 预览打印,调起系统打印预览
     * provider 左侧拖拽元素
     * template 模版json字符串
     * args 打印数据data, options,
     */
     globalVue.$print = function (provider = defaultElementTypeProvider, template, ...args) {
         hiprint.init({
            providers: [new provider()]
        });
        var hiprintTemplate = new hiprint.PrintTemplate({
            template: template,
        });
        hiprintTemplate.print(...args);
        return hiprintTemplate;
     }
     /**
    * 单模版直接打印, 需客户端支持
      * provider 左侧拖拽项对象
      * template 模版json字符串
      * args 打印数据data, options,
      */
     globalVue.$print2 = function (provider = defaultElementTypeProvider, template, ...args) {
         hiprint.init({
            providers: [new provider()]
        });
        var hiprintTemplate = new hiprint.PrintTemplate({
            template: template,
        });
        hiprintTemplate.print2(...args);
        return hiprintTemplate;
     }
  }
}
 
hiprint.version = version
 
window.hiprint = hiprint;
export {
  autoConnect,
  disAutoConnect,
  hiprint,
  hiPrintPlugin,
  defaultElementTypeProvider,
}