<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>
|