This commit is contained in:
wuyy 2026-07-13 14:28:39 +08:00
parent 6a7be0f67d
commit 61e89c365c
3 changed files with 51 additions and 2 deletions

View File

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

View File

@ -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)
}
}

View File

@ -88,6 +88,10 @@
<el-button type="primary" plain icon="Upload" :loading="printLoading" :size="aotuSize"
@click="printPdf">打印报告</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="primary" plain icon="download" :loading="downLoading" :size="aotuSize"
@click="downloadPdf">下载报告</el-button>
</el-col>
<!-- <right-toolbar v-model:showSearch="showSearch" @updateColumns="updateColumns" @queryTable="handleQuery"
:columns="columns"></right-toolbar> -->
@ -303,7 +307,7 @@ const resetQuery = () => {
queryRef.value?.resetFields();
getList()
}
const downLoading = ref(false);
const loading = ref(false);
// 勾选框数据
const rows = ref<any[]>([])
@ -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;