emis-app/components/tpx-bluetooth-print/render-template-native.vue

100 lines
2.6 KiB
Vue
Raw Normal View History

2024-05-14 17:00:36 +00:00
<template>
<tpx-bluetooth-native ref="curBlueTooth">
2024-06-25 04:09:42 +00:00
<template v-slot:content></template>
2024-05-14 17:00:36 +00:00
</tpx-bluetooth-native>
2024-06-25 04:09:42 +00:00
<!-- 打印进度 -->
<tpx-dialog type="type-dialog" title="打印中" :show="prtPercentage">
2024-05-14 17:00:36 +00:00
<u-row custom-style="width: 500rpx;min-height: 150rpx;padding: 10rpx;">
<view>
2024-06-25 04:09:42 +00:00
<u-line-progress :percentage="prtPercentage" activeColor="#B12D29" height="30"></u-line-progress>
2024-06-23 13:13:25 +00:00
<view class="pt-20">正在发送数据, 请勿退出页面, 如果卡住了请重连打印机重试</view>
2024-05-14 17:00:36 +00:00
</view>
</u-row>
</tpx-dialog>
</template>
<script>
import { showLoading, showToast, hideLoading, canvasGetImageData, getImageInfo, promiseTimeout } from "@/common/untool"
import * as canvasUtil from "@/common/canvasUtil"
2024-06-23 02:54:24 +00:00
import tanexPrinterUniSdk from './nativePrint/tanexPrinterUniSdk'
import printModule from './nativePrint/print'
2024-06-23 07:32:32 +00:00
import dayjs from "dayjs"
2024-05-14 17:00:36 +00:00
export default {
props:{
},
computed: {
},
data () {
return {
2024-06-25 04:09:42 +00:00
prtPercentage: 0, // 打印进度
2024-06-24 18:35:58 +00:00
paperWidth: 480,
2024-06-25 04:09:42 +00:00
imgRes: {},
2024-05-14 17:00:36 +00:00
}
},
mounted () {
this.initData()
},
unmounted() {
},
methods: {
async initData() {
},
// 打印
handlePrint(){
const that = this
return new Promise(async (resolve, reject)=> {
2024-06-06 17:21:48 +00:00
let { bl, deviceId } = that.checkPrintParam()
2024-05-14 17:00:36 +00:00
if(!bl) {
return reject('打印参数校验不通过')
}
2024-06-06 17:21:48 +00:00
let prtInstance = tanexPrinterUniSdk.createInstance()
2024-06-25 04:09:42 +00:00
// prtInstance.init(that.imgRes.height)
// prtInstance.diyCode(`PAGE-WIDTH 600\r\n`)
prtInstance.addBitmapByEG(0, 0, that.imgRes.imgData)
2024-06-06 17:21:48 +00:00
prtInstance.setPagePrint()
let commond = prtInstance.getPrintCmd()
2024-06-22 17:06:21 +00:00
console.log("打印命令组装完成,开始打印=====", commond)
2024-06-23 02:54:24 +00:00
printModule.print(commond)
2024-06-24 10:46:05 +00:00
that.showToast('数据发送成功,如果无法打印请重连设备重试')
2024-06-25 04:09:42 +00:00
resolve(true)
2024-06-24 10:46:05 +00:00
// await that.loadPrintProcess()
2024-06-21 16:11:54 +00:00
// printModule.printTestSimple(deviceId)
2024-05-14 17:00:36 +00:00
})
},
checkPrintParam() {
let msg = '', bl = false
2024-06-23 08:19:00 +00:00
let { deviceId, isStateOn } = this.$refs.curBlueTooth.getConData()
2024-06-25 04:09:42 +00:00
!this.imgRes.imgData && (msg = '打印内容不能为空,请重试')
2024-06-23 08:19:00 +00:00
if(!msg && !(deviceId && isStateOn)) {
msg = '未连接打印设备'
2024-05-14 17:00:36 +00:00
}
msg && (showToast(msg))
return {
2024-06-06 17:21:48 +00:00
deviceId,
2024-05-14 17:00:36 +00:00
msg,
bl: !msg
}
},
// 给外部调用api,打印自定义图
2024-06-25 04:09:42 +00:00
async callPrint({ paperWidth, imgRes } = {}) {
2024-06-25 08:13:45 +00:00
this.paperWidth = paperWidth || this.paperWidth
this.imgRes = imgRes
let conSta = await this.$refs.curBlueTooth.autoConnect()
this.$emit('autoConnectCallback', conSta)
if(conSta) {
await this.handlePrint()
return true
2024-05-14 17:00:36 +00:00
}
}
}
}
</script>
<style scoped lang="scss">
2024-06-25 04:09:42 +00:00
2024-05-14 17:00:36 +00:00
</style>