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