uu
This commit is contained in:
parent
1717b647f1
commit
434f244a54
@ -34,9 +34,6 @@ export default {
|
|||||||
prtPercentage: 0, // 打印进度
|
prtPercentage: 0, // 打印进度
|
||||||
paperWidth: 560,
|
paperWidth: 560,
|
||||||
imgRes: {},
|
imgRes: {},
|
||||||
prtQueList: [],
|
|
||||||
lastExeMark: undefined,
|
|
||||||
prtLoading: false,
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
@ -66,6 +63,7 @@ export default {
|
|||||||
console.log("打印命令组装完成,开始打印=====", commond)
|
console.log("打印命令组装完成,开始打印=====", commond)
|
||||||
printModule.print(commond)
|
printModule.print(commond)
|
||||||
that.showToast('数据发送成功,如果无法打印请重连设备重试')
|
that.showToast('数据发送成功,如果无法打印请重连设备重试')
|
||||||
|
await promiseTimeout(3000) // 发送数据差不多需要 3s
|
||||||
resolve(true)
|
resolve(true)
|
||||||
// await that.loadPrintProcess()
|
// await that.loadPrintProcess()
|
||||||
// printModule.printTestSimple(deviceId)
|
// printModule.printTestSimple(deviceId)
|
||||||
@ -86,37 +84,28 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 给外部调用api,打印自定义图
|
// 给外部调用api,打印自定义图
|
||||||
async callPrint(obj) {
|
async callPrint({ paperWidth, imgsRes }) {
|
||||||
this.prtQueList.push(obj)
|
|
||||||
clearTimeout(this.lastExeMark)
|
|
||||||
this.lastExeMark = setTimeout(()=> {
|
|
||||||
// if(this.prtLoading) {
|
|
||||||
// showToast('当前有打印任务未结束,请稍后再试')
|
|
||||||
// return false
|
|
||||||
// }
|
|
||||||
this.finallyExecPrint()
|
|
||||||
}, 500)
|
|
||||||
},
|
|
||||||
|
|
||||||
async finallyExecPrint() {
|
|
||||||
this.prtLoading = true
|
this.prtLoading = true
|
||||||
let conSta = await this.$refs.curBlueTooth.autoConnect()
|
let conSta = await this.$refs.curBlueTooth.autoConnect()
|
||||||
this.$emit('autoConnectCallback', conSta)
|
this.$emit('autoConnectCallback', conSta)
|
||||||
|
if(!Array.isArray(imgsRes)) {
|
||||||
for(let i = 0; i < this.prtQueList.length; i ++) {
|
imgsRes = [imgsRes]
|
||||||
let { paperWidth, imgRes } = this.prtQueList[i]
|
}
|
||||||
if(imgRes) {
|
|
||||||
this.paperWidth = paperWidth || this.paperWidth
|
|
||||||
this.imgRes = imgRes
|
|
||||||
if(conSta) {
|
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()
|
await this.handlePrint()
|
||||||
this.prtQueList[i] = undefined // 打印成功 清除当前数据
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
hideLoading()
|
||||||
this.prtQueList = []
|
|
||||||
this.prtLoading = false
|
|
||||||
return true
|
return true
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -91,6 +91,8 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
async startPrint({ imageUrl, paperWidth } = {}, preview = true) {
|
async startPrint({ imageUrl, paperWidth } = {}, preview = true) {
|
||||||
|
this.imageUrl = [] // 每次打印前,清空历史数据
|
||||||
|
|
||||||
// 默认先做预览
|
// 默认先做预览
|
||||||
if(imageUrl.length > 0) {
|
if(imageUrl.length > 0) {
|
||||||
if(!Array.isArray(imageUrl)){
|
if(!Array.isArray(imageUrl)){
|
||||||
@ -108,12 +110,14 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
async confirmPrint(){
|
async confirmPrint(){
|
||||||
this.imageUrl.map(async (url, index)=> {
|
let allRes = this.imageUrl.map((url, index)=> {
|
||||||
// !!!注意:必须修改。 canvas渲染的图必须修改url,否则渲染不出来
|
// !!!注意:必须修改。 canvas渲染的图必须修改url,否则渲染不出来
|
||||||
url = `${url}?t=${new Date().valueOf()}`
|
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({
|
let res = await this.$refs.curPrint.callPrint({
|
||||||
imgRes,
|
imgsRes,
|
||||||
paperWidth: this.paperWidth
|
paperWidth: this.paperWidth
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user