From 4fc797c55209fab424be10c43eef8172be2f7038 Mon Sep 17 00:00:00 2001 From: aihe <961836564@qq.com> Date: Sun, 12 May 2024 15:46:52 +0800 Subject: [PATCH] uu --- components/tpx-bluetooth-print/tpx-bluetooth-print.vue | 10 +++++----- components/tpx-bluetooth/tpx-bluetooth.vue | 8 +++++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/components/tpx-bluetooth-print/tpx-bluetooth-print.vue b/components/tpx-bluetooth-print/tpx-bluetooth-print.vue index 0a6c26c..13bb4f3 100644 --- a/components/tpx-bluetooth-print/tpx-bluetooth-print.vue +++ b/components/tpx-bluetooth-print/tpx-bluetooth-print.vue @@ -133,13 +133,13 @@ export default { this.canvasWidth = w this.canvasHeight = h // 在canvas 画一张图片 - // ctx.fillStyle = 'rgba(255,255,255,1)'; - ctx.clearRect(0, 0, w, h); - ctx.fillRect(0, 0, w, h); - let imgRect = canvasUtil.containImg(0, 0, w, h, res.width, res.height) + let ctData = [imgRect.dx, imgRect.dy, imgRect.dWidth, imgRect.dHeight] + ctx.fillStyle = 'rgba(255,255,255,1)'; + ctx.clearRect(...ctData); + ctx.fillRect(...ctData); // 把原图缩放到 打印宽度的比例 绘制 - ctx.drawImage(filePath, imgRect.dx, imgRect.dy, imgRect.dWidth, imgRect.dHeight); + ctx.drawImage(filePath, ...ctData); ctx.draw(false, () => { setTimeout( async ()=> { diff --git a/components/tpx-bluetooth/tpx-bluetooth.vue b/components/tpx-bluetooth/tpx-bluetooth.vue index f2c1fd8..29599d2 100644 --- a/components/tpx-bluetooth/tpx-bluetooth.vue +++ b/components/tpx-bluetooth/tpx-bluetooth.vue @@ -155,6 +155,7 @@ export default { }, unmounted() { this.stopDiscoveryPrinter() + this.closeBluetoothAdapter() }, methods: { changeTab(type) { @@ -202,7 +203,12 @@ export default { // 停止搜寻附近的蓝牙外围设备 async stopDiscoveryPrinter () { this.searchLoading = false - uni.stopBluetoothDevicesDiscovery() + uni?.stopBluetoothDevicesDiscovery?.() + }, + // 断开蓝牙 + async closeBluetoothAdapter () { + this.searchLoading = false + uni?.closeBluetoothAdapter?.() }, async handleSelectDeviceId (item) { this.deviceId = item.deviceId