干燥机配套车间生产管理系统/云平台服务端
baoshiwei
2024-05-27 fa3ac93010bea3805438ee3ab0a182bfbf7423da
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
import { nextTick } from 'vue';
import $printJS, { Configuration } from 'print-js';
import Print from 'vue-print-nb-jeecg/src/printarea';
 
/**
 * 调用 printJS,如果type = html,就走 printNB 的方法
 */
export function printJS(configuration: Configuration) {
  if (configuration?.type === 'html') {
    printNb(configuration.printable);
  } else {
    return $printJS(configuration);
  }
}
 
/** 调用 printNB 打印 */
export function printNb(domId) {
  if (domId) {
    localPrint(domId);
  } else {
    window.print();
  }
}
 
let closeBtn = true;
 
function localPrint(domId) {
  if (typeof domId === 'string' && !domId.startsWith('#')) {
    domId = '#' + domId;
  }
  nextTick(() => {
    if (closeBtn) {
      closeBtn = false;
      new Print({
        el: domId,
        endCallback() {
          closeBtn = true;
        },
      });
    }
  });
}