From a006636a2b43ac822f085da8cffc5c0033bfb491 Mon Sep 17 00:00:00 2001
From: aihe <961836564@qq.com>
Date: Tue, 25 Jun 2024 02:19:58 +0800
Subject: [PATCH] uu
---
.../tpx-bluetooth-native.vue | 6 +-
.../render-template-native.vue | 12 +-
.../tpx-bluetooth-print/render-template.vue | 13 +--
.../tpx-bluetooth-print.vue | 107 ++++++++++++------
4 files changed, 84 insertions(+), 54 deletions(-)
diff --git a/components/tpx-bluetooth-native/tpx-bluetooth-native.vue b/components/tpx-bluetooth-native/tpx-bluetooth-native.vue
index e709f1f..31f398f 100644
--- a/components/tpx-bluetooth-native/tpx-bluetooth-native.vue
+++ b/components/tpx-bluetooth-native/tpx-bluetooth-native.vue
@@ -15,15 +15,15 @@
- 蓝牙设备
+ 打印设备
{{deviceName || '-'}}
{{isStateOn?'已连接':'未连接'}}
-
+
diff --git a/components/tpx-bluetooth-print/render-template-native.vue b/components/tpx-bluetooth-print/render-template-native.vue
index 3220727..1b88d9a 100644
--- a/components/tpx-bluetooth-print/render-template-native.vue
+++ b/components/tpx-bluetooth-print/render-template-native.vue
@@ -1,8 +1,5 @@
-
- 打印
-
@@ -43,7 +40,7 @@ export default {
imgData: '',
percentage: 0, // 打印进度
imageUrl: '',
- paperWidth: 480,
+ paperWidth: 560,
}
},
mounted () {
@@ -65,7 +62,7 @@ export default {
}
let prtInstance = tanexPrinterUniSdk.createInstance()
prtInstance.init(that.canvasHeight)
- prtInstance.diyCode(`PAGE-WIDTH 600\r\n`)
+ // prtInstance.diyCode(`PAGE-WIDTH 600\r\n`)
prtInstance.addBitmapByEG(0, 0, that.imgData)
prtInstance.setPagePrint()
let commond = prtInstance.getPrintCmd()
@@ -74,7 +71,6 @@ export default {
that.showToast('数据发送成功,如果无法打印请重连设备重试')
// await that.loadPrintProcess()
// printModule.printTestSimple(deviceId)
-
})
},
// 模拟打印进度, 用于加载进度条
@@ -152,12 +148,14 @@ export default {
// 给外部调用api,打印自定义图
async callPrint({ paperWidth, imageUrl } = {}) {
try{
- this.paperWidth = paperWidth
+ this.paperWidth = paperWidth || this.paperWidth
if(this.imageUrl != imageUrl || !this.imgData) {
this.imageUrl = imageUrl
await this.renderCanvasImg(this.imageUrl);
}
let conSta = await this.$refs.curBlueTooth.autoConnect()
+ this.$emit('autoConnectCallback', conSta)
+
if(conSta) {
await this.handlePrint()
return true
diff --git a/components/tpx-bluetooth-print/render-template.vue b/components/tpx-bluetooth-print/render-template.vue
index 8d7c7e0..ae6a32f 100644
--- a/components/tpx-bluetooth-print/render-template.vue
+++ b/components/tpx-bluetooth-print/render-template.vue
@@ -1,10 +1,6 @@
-
- 确认打印
-
- 打印内容
@@ -43,7 +39,7 @@ export default {
percentage: 0, // 打印进度
threshold: 200, // 阈值(值越大,图片打印越深)
imageUrl: '',
- paperWidth: 480,
+ paperWidth: 560,
}
},
mounted () {
@@ -167,6 +163,7 @@ export default {
await this.renderCanvasImg(this.imageUrl);
}
let conSta = await this.$refs.curBlueTooth.autoConnect()
+ this.$emit('autoConnectCallback', conSta)
if(conSta) {
await this.handlePrint()
return true
@@ -185,8 +182,8 @@ export default {
}
/*图片隐藏到窗口外*/
canvas {
- // position: absolute;
- // z-index: -999;
- // top: -999px;
+ position: absolute;
+ z-index: -999;
+ top: -999px;
}
\ No newline at end of file
diff --git a/components/tpx-bluetooth-print/tpx-bluetooth-print.vue b/components/tpx-bluetooth-print/tpx-bluetooth-print.vue
index 458b2a5..07828c5 100644
--- a/components/tpx-bluetooth-print/tpx-bluetooth-print.vue
+++ b/components/tpx-bluetooth-print/tpx-bluetooth-print.vue
@@ -1,22 +1,45 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 确认打印
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -27,22 +50,19 @@ import { promiseTimeout } from "@/common/untool"
export default {
props:{
- type: {
- default () {
- return 'modal'
- }
- },
+
},
computed: {
-
},
components: {
RenderTemplate, RenderTemplate
},
data () {
return {
- imageUrl: '',
- paperWidth: 480,
+ previewModel: { show: false },
+ printModel: { show: false },
+ imageUrl: [],
+ paperWidth: 560,
show: false,
}
},
@@ -55,24 +75,39 @@ export default {
},
methods: {
handleCloseModal(){
- this.$emit('update:show', false)
- this.$emit('onClose')
},
- async startPrint({ imageUrl, paperWidth } = {}) {
+ handlePreview(index){
+ uni.previewImage({
+ urls: this.imageUrl,
+ current:index
+ })
+ },
+ async startPrint({ imageUrl, paperWidth } = {}, preview = true) {
+ // 默认先做预览
if(imageUrl.length > 0) {
- if(Array.isArray(imageUrl)){
- imageUrl = imageUrl[0]
+ if(!Array.isArray(imageUrl)){
+ imageUrl = [imageUrl]
}
this.imageUrl = imageUrl
this.paperWidth = paperWidth || this.paperWidth
- this.show = true
- let res = await this.$refs.curPrint.callPrint({
- imageUrl,
- paperWidth: this.paperWidth
- })
+ if(preview) {
+ this.previewModel.show = true
+ } else {
+ this.confirmPrint()
+ }
} else {
this.showToast('缺少打印内容')
}
+ },
+ async confirmPrint(){
+ let res = await this.$refs.curPrint.callPrint({
+ imageUrl: this.imageUrl[0],
+ paperWidth: this.paperWidth
+ })
+ },
+ autoConnectCallback(bl){
+ // 如果打印设备连接失败 需要显示打印设备弹框
+ this.printModel.show = !bl
}
}
}