From cf3fbfdfbc47e8b23f918f0be0841199c2ea725c Mon Sep 17 00:00:00 2001 From: taqi be Date: Thu, 23 Jan 2025 18:12:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8A=A5=E5=91=8A=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/module/eam/device/index.ts | 10 +++++ src/pages/deviceInfo/index.vue | 64 +++++++++++++++++++++++++----- 2 files changed, 65 insertions(+), 9 deletions(-) diff --git a/src/api/module/eam/device/index.ts b/src/api/module/eam/device/index.ts index d450d87..eed17ca 100644 --- a/src/api/module/eam/device/index.ts +++ b/src/api/module/eam/device/index.ts @@ -100,6 +100,16 @@ export const getDeviceLabelBase64 = (id: number) => params: { id }, }) +export const getDeviceReportPDF = (id: number) => { + return eamServer({ + url: `/report/general-report`, + method: 'get', + params: { id }, + timeout: 0, + responseType: 'blob', // 设置响应类型为 blob + }) +} + // ============== 测试工单相关 ============== export const operantDeviceTestSheet = (type: OperantAction, params: any) => { diff --git a/src/pages/deviceInfo/index.vue b/src/pages/deviceInfo/index.vue index b55500b..a49eb76 100644 --- a/src/pages/deviceInfo/index.vue +++ b/src/pages/deviceInfo/index.vue @@ -60,13 +60,6 @@ inner-text="查看" @click="onView(scope.row)" /> - - 更多 出库 + + + 打印标签 + + + + 打印测试报告 + + 设备报修 @@ -109,8 +119,10 @@ import { getDeviceLabelBase64, getDevicePage, getDeviceSummaryByStatus, + getDeviceReportPDF, type IDevice, } from '@/api/module/eam/device' +import { ElLoading } from 'element-plus' import { deviceTableCol, DeviceStatus } from './utils' import { getCategoryTree, type ICategoryTree } from '@/api/module/eam/device/category' import jsPDF from 'jspdf' @@ -196,7 +208,9 @@ function onView(row: any) { } async function onPrint(row: any) { + setLoadingPrint() const res = await getDeviceLabelBase64(row.id) + closeLoadingPrint() if (isResError(res)) return const pdf = new jsPDF('l', 'mm', [60, 40]) @@ -204,15 +218,47 @@ async function onPrint(row: any) { const imgWidth = 60 const imgHeight = 40 - // 添加图片到标签的 PDF 中 pdf.addImage(imgData, 'JPEG', 0, 0, imgWidth, imgHeight) - // 打开 PDF 打印对话框 pdf.autoPrint() window.open(pdf.output('bloburl'), '_blank') } +const loadingPrint = ref() +function setLoadingPrint() { + loadingPrint.value = ElLoading.service({ + lock: true, + text: '打印中请稍等...', + spinner: 'el-icon-loading', + background: 'rgba(0, 0, 0, 0.7)', + }) +} + +function closeLoadingPrint() { + loadingPrint.value.close() +} + +async function onPrintReport(row: any) { + setLoadingPrint() + const res = await getDeviceReportPDF(row.id) + closeLoadingPrint() + if (isResError(res)) return + const pdfURL = URL.createObjectURL(res.data) + const printWindow = window.open(pdfURL) as any + printWindow.onload = () => { + printWindow.print() + } +} + function handleCommand(command: string, row: any) { + if (command === 'printReport') { + onPrintReport(row) + return + } else if (command === 'printLabel') { + onPrint(row) + return + } + editDevice(row, command) }