Browse Source

feat: 报告打印

master
taqi be 1 month ago
parent
commit
cf3fbfdfbc
  1. 10
      src/api/module/eam/device/index.ts
  2. 64
      src/pages/deviceInfo/index.vue

10
src/api/module/eam/device/index.ts

@ -100,6 +100,16 @@ export const getDeviceLabelBase64 = (id: number) => @@ -100,6 +100,16 @@ export const getDeviceLabelBase64 = (id: number) =>
params: { id },
})
export const getDeviceReportPDF = (id: number) => {
return eamServer<Blob>({
url: `/report/general-report`,
method: 'get',
params: { id },
timeout: 0,
responseType: 'blob', // 设置响应类型为 blob
})
}
// ============== 测试工单相关 ==============
export const operantDeviceTestSheet = (type: OperantAction, params: any) => {

64
src/pages/deviceInfo/index.vue

@ -60,13 +60,6 @@ @@ -60,13 +60,6 @@
inner-text="查看"
@click="onView(scope.row)"
/><el-divider direction="vertical" />
<EdfsButton
link
type="primary"
inner-text="打印标签"
@click="onPrint(scope.row)"
/><el-divider direction="vertical" />
<el-dropdown @command="command => handleCommand(command, scope.row)">
<el-button type="primary" link
><Icon icon="ep:d-arrow-right" /> 更多</el-button
@ -82,6 +75,23 @@ @@ -82,6 +75,23 @@
<el-dropdown-item command="delivery" v-if="scope.row.status === 2">
<Icon icon="solar:inbox-out-outline" />出库
</el-dropdown-item>
<el-dropdown-menu>
<Icon
icon="solar:printer-outline"
command="printLabel "
v-if="scope.row.status >= 1"
/>
打印标签
</el-dropdown-menu>
<el-dropdown-menu>
<Icon
icon="solar:printer-outline"
command="printReport"
v-if="scope.row.status >= 2"
/>
打印测试报告
</el-dropdown-menu>
<el-dropdown-item command="maintain" v-if="scope.row.status >= 3">
<Icon icon="solar:minimalistic-magnifer-bug-outline" />设备报修
</el-dropdown-item>
@ -109,8 +119,10 @@ import { @@ -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) { @@ -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) { @@ -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<any>()
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)
}

Loading…
Cancel
Save