index.js 2.1 KB

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