diff --git a/src/utils/classCom.ts b/src/utils/classCom.ts index 55737d6..5b30079 100644 --- a/src/utils/classCom.ts +++ b/src/utils/classCom.ts @@ -104,6 +104,34 @@ function base64ToBlob(base64: string) { return new Blob([bytes], { type: 'application/pdf' }); } +// 下载 PDF(纯 Base64 格式,不带前缀) +const downloadPdfReport = (base64Data, fileName = "检验报告.pdf") => { + + // 1. 解码 Base64 + const raw = window.atob(base64Data); + const len = raw.length; + const uInt8Array = new Uint8Array(len); + + for (let i = 0; i < len; i++) { + uInt8Array[i] = raw.charCodeAt(i); + } + + // 2. 构建 Blob + const blob = new Blob([uInt8Array], { + type: "application/pdf", + }); + + // 3. 创建下载链接 + const link = document.createElement("a"); + link.href = URL.createObjectURL(blob); + link.download = fileName; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + URL.revokeObjectURL(link.href); + +}; + // 计算两个日期的天数差(支持带时分秒) const getDayDiff = (start: string, end: string): number => { const startTime = new Date(start).getTime(); @@ -160,4 +188,4 @@ function useAutoSize() { return autoSize; } -export const classCom = { decimalToHexColor, convertHexToNumber, getContrastTextColor, printBase64PDF, printPDF, useAutoSize, getDayDiff } +export const classCom = { decimalToHexColor, convertHexToNumber, getContrastTextColor, printBase64PDF, printPDF, downloadPdfReport, useAutoSize, getDayDiff } diff --git a/src/utils/printHelper.ts b/src/utils/printHelper.ts index 048e279..889729b 100644 --- a/src/utils/printHelper.ts +++ b/src/utils/printHelper.ts @@ -30,6 +30,7 @@ export const showPrintServiceError = async (msg: string) => { if (!(window as any).downExe) { (window as any).downExe = () => { Download.name('lisprintsetup.exe', false) + Download.name('Gprinter_12.4.0.exe', false) } } diff --git a/src/views/regional/inspectionReport/report/index.vue b/src/views/regional/inspectionReport/report/index.vue index 9891be3..3269111 100644 --- a/src/views/regional/inspectionReport/report/index.vue +++ b/src/views/regional/inspectionReport/report/index.vue @@ -88,6 +88,10 @@ 打印报告 + + 下载报告 + @@ -303,7 +307,7 @@ const resetQuery = () => { queryRef.value?.resetFields(); getList() } - +const downLoading = ref(false); const loading = ref(false); // 勾选框数据 const rows = ref([]) @@ -409,6 +413,22 @@ const printPdf = () => { }) } +//下载报告 +const downloadPdf = () => { + if (!Info.value) return ElMessage.warning('请选择一条数据') + downLoading.value = true + reportPrintPdf({ bgdh: Info.value.bgdh }).then((res) => { + if (res.code == 0) { + if (!res.data) return ElMessage.warning('未找到下载文件') + classCom.downloadPdfReport(res.data) + ElMessage.success('正在下载中...') + handleQuery() + } + }).finally(() => { + downLoading.value = false + }) +} + // 单元格样式 const cellStyleHd = ({ row, column, rowIndex, columnIndex }: { row: any;