From 434f244a54fcb82363bb9643b9a85acc44620e87 Mon Sep 17 00:00:00 2001 From: aihe <961836564@qq.com> Date: Wed, 26 Jun 2024 00:48:25 +0800 Subject: [PATCH] uu --- .../render-template-native.vue | 43 +++++++------------ .../tpx-bluetooth-print.vue | 10 +++-- 2 files changed, 23 insertions(+), 30 deletions(-) diff --git a/components/tpx-bluetooth-print/render-template-native.vue b/components/tpx-bluetooth-print/render-template-native.vue index b15cc54..d70c48c 100644 --- a/components/tpx-bluetooth-print/render-template-native.vue +++ b/components/tpx-bluetooth-print/render-template-native.vue @@ -34,9 +34,6 @@ export default { prtPercentage: 0, // 打印进度 paperWidth: 560, imgRes: {}, - prtQueList: [], - lastExeMark: undefined, - prtLoading: false, } }, mounted () { @@ -66,6 +63,7 @@ export default { console.log("打印命令组装完成,开始打印=====", commond) printModule.print(commond) that.showToast('数据发送成功,如果无法打印请重连设备重试') + await promiseTimeout(3000) // 发送数据差不多需要 3s resolve(true) // await that.loadPrintProcess() // printModule.printTestSimple(deviceId) @@ -86,37 +84,28 @@ export default { } }, // 给外部调用api,打印自定义图 - async callPrint(obj) { - this.prtQueList.push(obj) - clearTimeout(this.lastExeMark) - this.lastExeMark = setTimeout(()=> { - // if(this.prtLoading) { - // showToast('当前有打印任务未结束,请稍后再试') - // return false - // } - this.finallyExecPrint() - }, 500) - }, - - async finallyExecPrint() { + async callPrint({ paperWidth, imgsRes }) { this.prtLoading = true let conSta = await this.$refs.curBlueTooth.autoConnect() this.$emit('autoConnectCallback', conSta) - - for(let i = 0; i < this.prtQueList.length; i ++) { - let { paperWidth, imgRes } = this.prtQueList[i] - if(imgRes) { - this.paperWidth = paperWidth || this.paperWidth - this.imgRes = imgRes - if(conSta) { + if(!Array.isArray(imgsRes)) { + imgsRes = [imgsRes] + } + if(conSta) { + showLoading() + for(let i = 0; i < imgsRes.length; i ++) { + let item = imgsRes[i] + if(item) { + this.paperWidth = paperWidth || this.paperWidth + this.imgRes = item await this.handlePrint() - this.prtQueList[i] = undefined // 打印成功 清除当前数据 } } + hideLoading() + return true + } else { + return false } - this.prtQueList = [] - this.prtLoading = false - return true } } } diff --git a/components/tpx-bluetooth-print/tpx-bluetooth-print.vue b/components/tpx-bluetooth-print/tpx-bluetooth-print.vue index 05d3c10..5051345 100644 --- a/components/tpx-bluetooth-print/tpx-bluetooth-print.vue +++ b/components/tpx-bluetooth-print/tpx-bluetooth-print.vue @@ -91,6 +91,8 @@ export default { }) }, async startPrint({ imageUrl, paperWidth } = {}, preview = true) { + this.imageUrl = [] // 每次打印前,清空历史数据 + // 默认先做预览 if(imageUrl.length > 0) { if(!Array.isArray(imageUrl)){ @@ -108,12 +110,14 @@ export default { } }, async confirmPrint(){ - this.imageUrl.map(async (url, index)=> { + let allRes = this.imageUrl.map((url, index)=> { // !!!注意:必须修改。 canvas渲染的图必须修改url,否则渲染不出来 url = `${url}?t=${new Date().valueOf()}` - let imgRes = await this.$refs[`curCanvas${index}`][0].renderCanvasImg(url, this.paperWidth) + return this.$refs[`curCanvas${index}`][0].renderCanvasImg(url, this.paperWidth) + }) + Promise.all(allRes).then(async (imgsRes)=> { let res = await this.$refs.curPrint.callPrint({ - imgRes, + imgsRes, paperWidth: this.paperWidth }) })