uu
This commit is contained in:
parent
c56390a3f3
commit
9ade67d3aa
@ -120,14 +120,19 @@ var tanexPrinter = {
|
||||
data = `TEXT 24 0 10 10 ${text}\r\n`
|
||||
tanexPrinter.addCommand(data)
|
||||
};
|
||||
|
||||
// 设置走整张纸
|
||||
tanexPrinter.setFormPage = function() {
|
||||
data = "GAP-SENSE\r\n"
|
||||
data += "FORM \r\n" // 走一整页
|
||||
tanexPrinter.addCommand(data)
|
||||
};
|
||||
|
||||
/*
|
||||
[名称] 设置打印命令
[格式] {command}
[说明] {command}:PRINT
在CPCL 指令模式下,打印命令终止和打印文件,这是最后的一条命令;执行打印命
令后,打印机退出控制段,在打印命令后,必须跟一个回车。
如果打印中出错,等待错误恢复后重新打印。
[实例] Input:
! 0 200 200 210 1
……………
PRINT
|
||||
*/
|
||||
tanexPrinter.setPagePrint = function() {
|
||||
data = "GAP-SENSE\r\n"
|
||||
data += "FORM \r\n" // 走一整页
|
||||
data += "PRINT \r\n" // 开始打印
|
||||
tanexPrinter.setPagePrint = function() {
|
||||
data = "PRINT \r\n" // 开始打印
|
||||
tanexPrinter.addCommand(data)
|
||||
};
|
||||
|
||||
|
||||
@ -32,8 +32,7 @@ export default {
|
||||
data () {
|
||||
return {
|
||||
prtPercentage: 0, // 打印进度
|
||||
paperWidth: 560,
|
||||
imgRes: {},
|
||||
paperWidth: 600,
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
@ -47,23 +46,31 @@ export default {
|
||||
|
||||
},
|
||||
// 打印
|
||||
handlePrint(){
|
||||
handlePrint(imgsRes){
|
||||
const that = this
|
||||
return new Promise(async (resolve, reject)=> {
|
||||
let imgLen = imgsRes.length
|
||||
let { bl, deviceId } = that.checkPrintParam()
|
||||
if(!bl) {
|
||||
return reject('打印参数校验不通过')
|
||||
}
|
||||
let prtInstance = tanexPrinterUniSdk.createInstance()
|
||||
prtInstance.init(that.imgRes.height)
|
||||
prtInstance.init(
|
||||
imgsRes?.[0]?.height * imgLen // 总高度
|
||||
)
|
||||
// prtInstance.diyCode(`PAGE-WIDTH 600\r\n`)
|
||||
prtInstance.addBitmapByEG(0, 0, that.imgRes.imgData)
|
||||
for(let i = 0; i < imgsRes.length; i ++) {
|
||||
let item = imgsRes[i]
|
||||
if(item) {
|
||||
prtInstance.addBitmapByEG(0, 0, item.imgData)
|
||||
prtInstance.setFormPage() // 每张图打印一整页
|
||||
}
|
||||
}
|
||||
prtInstance.setPagePrint()
|
||||
let commond = prtInstance.getPrintCmd()
|
||||
console.log("打印命令组装完成,开始打印=====", commond)
|
||||
printModule.print(commond)
|
||||
that.showToast('数据发送成功,如果无法打印请重连设备重试')
|
||||
await promiseTimeout(3000) // 发送数据差不多需要 3s
|
||||
resolve(true)
|
||||
// await that.loadPrintProcess()
|
||||
// printModule.printTestSimple(deviceId)
|
||||
@ -72,7 +79,6 @@ export default {
|
||||
checkPrintParam() {
|
||||
let msg = '', bl = false
|
||||
let { deviceId, isStateOn } = this.$refs.curBlueTooth.getConData()
|
||||
!this.imgRes.imgData && (msg = '打印内容不能为空,请重试')
|
||||
if(!msg && !(deviceId && isStateOn)) {
|
||||
msg = '未连接打印设备'
|
||||
}
|
||||
@ -85,23 +91,14 @@ export default {
|
||||
},
|
||||
// 给外部调用api,打印自定义图
|
||||
async callPrint({ paperWidth, imgsRes }) {
|
||||
this.prtLoading = true
|
||||
this.paperWidth = paperWidth || this.paperWidth
|
||||
let conSta = await this.$refs.curBlueTooth.autoConnect()
|
||||
this.$emit('autoConnectCallback', 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()
|
||||
}
|
||||
}
|
||||
hideLoading()
|
||||
await this.handlePrint(imgsRes)
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
|
||||
@ -70,7 +70,7 @@ export default {
|
||||
previewModel: { show: false },
|
||||
printModel: { show: false },
|
||||
imageUrl: [],
|
||||
paperWidth: 560,
|
||||
paperWidth: 600,
|
||||
show: false,
|
||||
}
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user