This commit is contained in:
aihe 2024-06-26 00:48:25 +08:00
parent 1717b647f1
commit 434f244a54
2 changed files with 23 additions and 30 deletions

View File

@ -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
}
}
}

View File

@ -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
})
})