打印
This commit is contained in:
parent
6a7be0f67d
commit
61e89c365c
@ -104,6 +104,34 @@ function base64ToBlob(base64: string) {
|
|||||||
return new Blob([bytes], { type: 'application/pdf' });
|
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 getDayDiff = (start: string, end: string): number => {
|
||||||
const startTime = new Date(start).getTime();
|
const startTime = new Date(start).getTime();
|
||||||
@ -160,4 +188,4 @@ function useAutoSize() {
|
|||||||
return autoSize;
|
return autoSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const classCom = { decimalToHexColor, convertHexToNumber, getContrastTextColor, printBase64PDF, printPDF, useAutoSize, getDayDiff }
|
export const classCom = { decimalToHexColor, convertHexToNumber, getContrastTextColor, printBase64PDF, printPDF, downloadPdfReport, useAutoSize, getDayDiff }
|
||||||
|
|||||||
@ -30,6 +30,7 @@ export const showPrintServiceError = async (msg: string) => {
|
|||||||
if (!(window as any).downExe) {
|
if (!(window as any).downExe) {
|
||||||
(window as any).downExe = () => {
|
(window as any).downExe = () => {
|
||||||
Download.name('lisprintsetup.exe', false)
|
Download.name('lisprintsetup.exe', false)
|
||||||
|
Download.name('Gprinter_12.4.0.exe', false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -88,6 +88,10 @@
|
|||||||
<el-button type="primary" plain icon="Upload" :loading="printLoading" :size="aotuSize"
|
<el-button type="primary" plain icon="Upload" :loading="printLoading" :size="aotuSize"
|
||||||
@click="printPdf">打印报告</el-button>
|
@click="printPdf">打印报告</el-button>
|
||||||
</el-col>
|
</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"
|
<!-- <right-toolbar v-model:showSearch="showSearch" @updateColumns="updateColumns" @queryTable="handleQuery"
|
||||||
:columns="columns"></right-toolbar> -->
|
:columns="columns"></right-toolbar> -->
|
||||||
@ -303,7 +307,7 @@ const resetQuery = () => {
|
|||||||
queryRef.value?.resetFields();
|
queryRef.value?.resetFields();
|
||||||
getList()
|
getList()
|
||||||
}
|
}
|
||||||
|
const downLoading = ref(false);
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
// 勾选框数据
|
// 勾选框数据
|
||||||
const rows = ref<any[]>([])
|
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 }: {
|
const cellStyleHd = ({ row, column, rowIndex, columnIndex }: {
|
||||||
row: any;
|
row: any;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user