From 2db98513a78575f3917a80ea3a578dd28305b565 Mon Sep 17 00:00:00 2001 From: lion <120344285@qq.com> Date: Tue, 11 Nov 2025 17:07:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=87=E7=AD=BE=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/inventorys/index.vue | 2 +- src/views/myprint/index.vue | 126 ++++++++++++++++++++++++--------- 2 files changed, 93 insertions(+), 35 deletions(-) diff --git a/src/views/inventorys/index.vue b/src/views/inventorys/index.vue index 17969df..a335362 100644 --- a/src/views/inventorys/index.vue +++ b/src/views/inventorys/index.vue @@ -570,7 +570,7 @@ // } // Cookies.remove('objs') // Cookies.set('objs',JSON.stringify(_objs)) - window.open('/admin/print.html?ids=' + this.printArr, '_blank') + window.open('/admin/#/myprint?ids=' + this.printArr, '_blank') }, async exportExcel(sheetName) { const res = await index(Object.assign(this.select, { diff --git a/src/views/myprint/index.vue b/src/views/myprint/index.vue index b66d97c..231ae3d 100644 --- a/src/views/myprint/index.vue +++ b/src/views/myprint/index.vue @@ -6,7 +6,8 @@
- 批量打印 + 重新连接 + 批量打印 打印日志
@@ -59,7 +60,9 @@ export default { materialList: [], // 存储所有物资信息 imgList: [], // 存储所有图片路径 showLogDrawer: false, - logs: [] // { type: 'success'|'error'|'info', text: string, time: 'HH:mm:ss' } + logs: [], // { type: 'success'|'error'|'info', text: string, time: 'HH:mm:ss' } + isPrinting: false, + needsReconnect: false } }, async created() { @@ -69,7 +72,7 @@ export default { this.$message.error('请先选择物资') return } - + // 获取打印机信息 await this.getInfo() // 设置模版打印 @@ -80,6 +83,16 @@ export default { await this.changeLabelValue(false) }, methods: { + // 重新连接 + async reconnect() { + // 获取打印机信息 + await this.getInfo() + // 设置模版打印 + await this.getAllMaterialInfo() + // 更改每一个标签中的值 并生成预览图片 + await this.changeLabelValue(false) + this.needsReconnect = false + }, // 统一添加日志 addLog(type, text) { const two = n => (n < 10 ? '0' + n : '' + n) @@ -92,7 +105,7 @@ export default { const res = await sendPostRequestApi(funcId, funcName, data) if (res.rtnCode === '0') { if (showMessage) { - this.$message.success(funcName + '成功') + this.$message.success(funcName + '成功') } this.addLog('success', funcName + '成功') return res.outParams ? res.outParams : true @@ -113,9 +126,14 @@ export default { try { await this.sendPostRequest('web_DSTP2x_SetLibLang', '设置语言', { language: '0' }, true) //枚举设备 - const devRes = await this.sendPostRequest('web_DSTP2x_EnumDev', '获取打印设备', { + const devRes = await this.sendPostRequest( + 'web_DSTP2x_EnumDev', + '获取打印设备', + { enumType: '1' - }, true) + }, + true + ) console.log('devRes', devRes) const index = devRes.enumList.indexOf(',') if (index !== -1) { @@ -123,9 +141,14 @@ export default { devRes.enumList = devList[0] } // 连接打印设备 - this.connectRes = await this.sendPostRequest('web_DSTP2x_ConnEnumeratedDev', '连接打印设备', { + this.connectRes = await this.sendPostRequest( + 'web_DSTP2x_ConnEnumeratedDev', + '连接打印设备', + { devName: devRes.enumList - }, true) + }, + true + ) // 获取打印机序列号 const snRes = await this.sendPostRequest('web_DSTP2x_GetPrtSN', '获取打印机序列号', { devHdl: this.connectRes.devHdl @@ -143,9 +166,14 @@ export default { } // 获取打印状态 - const statusRes = await this.sendPostRequest('web_DSTP2x_GetPrtStatus', '获取打印状态', { + const statusRes = await this.sendPostRequest( + 'web_DSTP2x_GetPrtStatus', + '获取打印状态', + { devHdl: this.connectRes.devHdl - }, true) + }, + true + ) if (statusRes.prtStatusDesc) { const statusStr = this.getAllStatus( statusRes.mainStatusCode, @@ -178,10 +206,15 @@ export default { // 设置模版打印 async setTemplatePrint(isprint) { // 创建画布 - this.labelContent = await this.sendPostRequest('web_DSTP2x_CreateLabelContext', '创建画布', { - width: '80', - height: '40' - }, true) + this.labelContent = await this.sendPostRequest( + 'web_DSTP2x_CreateLabelContext', + '创建画布', + { + width: '80', + height: '40' + }, + true + ) if (this.labelContent) { // 设置文本字体 await this.sendPostRequest('web_DSTP2x_LcDraw_SetTextFontSize', '设置文本字体', { @@ -212,9 +245,10 @@ export default { { lcHdl: this.labelContent.lcHdl, prnMode: isprint ? '0' : '3' - }, true + }, + true ) - } else { + } else { this.$message.error('创建画布失败') } }, @@ -357,12 +391,17 @@ export default { data: hexId }) - const printRes = await this.sendPostRequest('web_DSTP2x_PrintLc', `第${index + 1}次打印`, { - devHdl: this.connectRes.devHdl, - lcHdl: this.labelContent.lcHdl, - outFileType: '1', - rfidReadType: '3' - }, true) + const printRes = await this.sendPostRequest( + 'web_DSTP2x_PrintLc', + `第${index + 1}次打印`, + { + devHdl: this.connectRes.devHdl, + lcHdl: this.labelContent.lcHdl, + outFileType: '1', + rfidReadType: '3' + }, + true + ) if (printRes) { if (!isprint) { this.imgList.push(printRes.outFile) @@ -371,24 +410,43 @@ export default { } } // 完成后清理 - await this.sendPostRequest('web_DSTP2x_DeleteLabelContext', `删除${index + 1}画布句柄`, { - lcHdl: this.labelContent.lcHdl - }, true) + await this.sendPostRequest( + 'web_DSTP2x_DeleteLabelContext', + `删除${index + 1}画布句柄`, + { + lcHdl: this.labelContent.lcHdl + }, + true + ) this.labelContent = '' } if (isprint) { - await this.sendPostRequest('web_DSTP2x_DisconnDev', '断开设备连接', { - devHdl: this.connectRes.devHdl - }, true) + await this.sendPostRequest( + 'web_DSTP2x_DisconnDev', + '断开设备连接', + { + devHdl: this.connectRes.devHdl + }, + true + ) + // 打印流程完成,需要重新连接 + this.needsReconnect = true } }, + // 批量打印 async batchPrint() { - // await this.sendPostRequest('web_DSTP2x_SetLcPrnMode', '设置标签画布的打印模式', { - // lcHdl: this.labelContent.lcHdl, - // prnMode: '0' - // }) - await this.changeLabelValue(true) + if (this.isPrinting) return + if (this.needsReconnect) { + this.$message.warning('请重新连接设备') + return + } + this.isPrinting = true + try { + await this.changeLabelValue(true) + } finally { + this.isPrinting = false + } }, // 获取所有物资信息 async getAllMaterialInfo() { @@ -410,7 +468,7 @@ export default { // 获取物资详情 async getMaterialInfo(id) { try { - const res = await getMaterialInfo({ id: id }) + const res = await getMaterialInfo({ id: id }) if (res) { return res }