From 54faa1a8d245ed64eb17e31b9d59bc14fa0cc05d Mon Sep 17 00:00:00 2001 From: aihe <961836564@qq.com> Date: Sun, 23 Jun 2024 15:32:32 +0800 Subject: [PATCH] uu --- .../render-template-native.vue | 18 ++++++++++-------- .../tpx-bluetooth-print.vue | 10 +++++----- pages/print/courierNote.vue | 1 - 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/components/tpx-bluetooth-print/render-template-native.vue b/components/tpx-bluetooth-print/render-template-native.vue index caff791..77cc8c6 100644 --- a/components/tpx-bluetooth-print/render-template-native.vue +++ b/components/tpx-bluetooth-print/render-template-native.vue @@ -26,6 +26,7 @@ import { showLoading, showToast, hideLoading, canvasGetImageData, getImageInfo, import * as canvasUtil from "@/common/canvasUtil" import tanexPrinterUniSdk from './nativePrint/tanexPrinterUniSdk' import printModule from './nativePrint/print' +import dayjs from "dayjs" export default { props:{ @@ -52,7 +53,7 @@ export default { }, methods: { async initData() { - await this.renderCanvasImg(this.imageUrl); + this.imageUrl && await this.renderCanvasImg(this.imageUrl); }, // 打印 handlePrint(){ @@ -81,11 +82,8 @@ export default { console.log("===renderCanvasImg:filePath=====", filePath) return new Promise(async (resolve, reject)=> { try{ - // 多次渲染,createCanvasContext,必须使用新的才可以 - that.canvasId = uni.$u.guid(20) - await promiseTimeout(500) let res = await getImageInfo(filePath) - console.log("getImageInfo res====", res) + console.log("getImageInfo res====", res) const ctx = uni.createCanvasContext(that.canvasId, that); // 打印宽度须是8的整数倍,这里处理掉多余的,使得宽度合适,不然有可能乱码 const remainder = that.paperWidth % 8; @@ -102,15 +100,19 @@ export default { ctx.fillRect(...ctData); // 把原图缩放到 打印宽度的比例 绘制 ctx.drawImage(filePath, ...ctData); - ctx.draw(false, async() => { - await promiseTimeout(1000) + // await promiseTimeout(1000) let imgData = await canvasGetImageData({ canvasId: that.canvasId, width: w, height: h, }) hideLoading() that.imgData = imgData + console.log("canvasGetImageData imgData.data.length =====", imgData.data.length) + // 多次渲染,createCanvasContext,必须使用新的才可以 + that.canvasId = uni.$u.guid(20) resolve() }); }catch(e){ + // 多次渲染,createCanvasContext,必须使用新的才可以 + that.canvasId = uni.$u.guid(20) hideLoading() reject(e) } @@ -140,7 +142,7 @@ export default { } let conSta = await this.$refs.curBlueTooth.autoConnect() if(conSta) { - await this.handlePrint() + // await this.handlePrint() return true } } catch(e){ diff --git a/components/tpx-bluetooth-print/tpx-bluetooth-print.vue b/components/tpx-bluetooth-print/tpx-bluetooth-print.vue index d9d604b..f7a8fe4 100644 --- a/components/tpx-bluetooth-print/tpx-bluetooth-print.vue +++ b/components/tpx-bluetooth-print/tpx-bluetooth-print.vue @@ -22,7 +22,7 @@