index.js 2.2 KB

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