刘光辉
3 小时以前 cf11e63b659afcc9792ab3e395f1b45d844431a8
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
<script lang="ts" setup>
import { onMounted, onUnmounted, ref } from 'vue';
 
import { useModal } from '@jnpf/ui/modal';
 
import CustomPrintModal from '#/components/CustomPrint/CustomPrintModal.vue';
import { onlineUtils } from '#/utils/jnpf';
import { buildPrintAuditTargets } from '#/utils/printAudit';
 
const emitter = onlineUtils.getEmitter();
 
const [registerCustomPrintModal, { openModal: openCustomPrintModal }] = useModal();
const activeConfig = ref<any>();
 
function handleOpenPrintModal(config: any) {
  activeConfig.value = config;
  setTimeout(() => {
    openCustomPrintModal(true, config);
  }, 100);
}
 
function handlePrint(data: any) {
  const config = activeConfig.value;
  try {
    if (config?.audit !== false) {
      const audit = config?.audit || {};
      const targets = audit.targets || buildPrintAuditTargets(data, audit);
      if (targets.length) {
        const printName = audit.printName || config?.title || '自定义打印';
        onlineUtils.auditPrint({
          bizType: audit.bizType,
          printName,
          recordTitle: audit.recordTitle || printName,
          source: 'CUSTOM_PRINT',
          targetTable: audit.targetTable,
          targets,
        });
      }
    }
    config?.onPrint?.(data);
  } catch (error) {
    console.error('[GlobalCustomPrintModal] 打印回调执行失败:', error);
  }
}
 
function handleDownloadPdf(data: any) {
  try {
    activeConfig.value?.onDownloadPdf?.(data);
  } catch (error) {
    console.error('[GlobalCustomPrintModal] PDF 回调执行失败:', error);
  }
}
 
function handleError(error: any) {
  try {
    activeConfig.value?.onError?.(error);
  } catch (callbackError) {
    console.error('[GlobalCustomPrintModal] 错误回调执行失败:', callbackError);
  }
}
 
onMounted(() => {
  emitter.on('OPEN_PRINT_MODAL', handleOpenPrintModal);
});
 
onUnmounted(() => {
  emitter.off('OPEN_PRINT_MODAL', handleOpenPrintModal);
});
</script>
 
<template>
  <CustomPrintModal @register="registerCustomPrintModal" @print="handlePrint" @download-pdf="handleDownloadPdf" @error="handleError" />
</template>