From cf60414d7686194f35f41e6f1cf1dfe8f6e89765 Mon Sep 17 00:00:00 2001 From: liub Date: Mon, 27 Oct 2025 11:51:38 +0800 Subject: [PATCH] =?UTF-8?q?=E8=93=9D=E7=89=99=E6=96=AD=E5=BC=80=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E5=8F=98=E6=88=90=E5=BC=82=E6=AD=A5=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/100/HBY100.vue | 10 ++++----- utils/BleHelper.js | 50 +++++++++++++++++++------------------------- 2 files changed, 27 insertions(+), 33 deletions(-) diff --git a/pages/100/HBY100.vue b/pages/100/HBY100.vue index e602960..ea5a481 100644 --- a/pages/100/HBY100.vue +++ b/pages/100/HBY100.vue @@ -398,11 +398,11 @@ ble = BleTool.getBleTool(); - ble.addReceiveCallback(these.bleValueNotify, pagePath); - ble.addStateBreakCallback(these.bleStateBreak, pagePath); - ble.addStateRecoveryCallback(these.bleStateRecovry, pagePath); - ble.addDisposeCallback(these.deviceDispose, pagePath); - ble.addRecoveryCallback(these.deviceRecovry, pagePath); + ble.addReceiveCallback(this.bleValueNotify, pagePath); + ble.addStateBreakCallback(this.bleStateBreak, pagePath); + ble.addStateRecoveryCallback(this.bleStateRecovry, pagePath); + ble.addDisposeCallback(this.deviceDispose, pagePath); + ble.addRecoveryCallback(this.deviceRecovry, pagePath); let eventChannel = this.getOpenerEventChannel(); diff --git a/utils/BleHelper.js b/utils/BleHelper.js index ac03070..7a861bd 100644 --- a/utils/BleHelper.js +++ b/utils/BleHelper.js @@ -172,7 +172,7 @@ class BleHelper { //连接所有已连接过的设备 linkAllDevices() { // console.log("模块启动时,自动连接已连接过的设备", this.data.LinkedList); - if(this.data.platform=='web'){ + if (this.data.platform == 'web') { return; } if (this.data.LinkedList && this.data.LinkedList.length > 0) { @@ -1405,7 +1405,7 @@ class BleHelper { //连接某个设备 LinkBlue(deviceId, targetServiceId, writeCharId, notifyCharId, maxRetries) { - if(this.data.platform=='web'){ + if (this.data.platform == 'web') { return Promise.resolve(true); } if (maxRetries === undefined) { @@ -1595,7 +1595,7 @@ class BleHelper { } //断开连接 disconnectDevice(deviceId) { - if(this.data.platform=='web'){ + if (this.data.platform == 'web') { return Promise.resolve(); } var disconnect = (id) => { @@ -1616,16 +1616,7 @@ class BleHelper { } if (deviceId) { - disconnect(deviceId); - - this.data.LinkedList.find(v => { - if (v.deviceId === deviceId) { - return true; - } - return false; - }); - - return; + return disconnect(deviceId); } if (this.data.LinkedList.length > 0) { @@ -1637,23 +1628,26 @@ class BleHelper { } } - if (arr.length == 0) { - return; - } - - Promise.allSettled(arr).then((results) => { - results.forEach((result, index) => { - if (result.status === 'fulfilled') { - ////console.log(`第${index + 1}个Promise成功:`, result.value); - } else { - ////console.log(`第${index + 1}个Promise失败:`, result.reason.message); - } + if (arr.length) { + return new Promise((_succ, _err) => { + Promise.allSettled(arr).then((results) => { + results.forEach((result, index) => { + if (result.status === 'fulfilled') { + ////console.log(`第${index + 1}个Promise成功:`, result.value); + } else { + ////console.log(`第${index + 1}个Promise失败:`, result.reason.message); + } + }); + _succ() + }).catch((ex) => { + _err(); + }); }); - }); - - } else { - ////console.log("无已连接设备"); + } } + + return Promise.resolve(); + } //向蓝牙设备发送一个字符串的ASCII码 sendString(deviceid, str, writeServiceId, wirteCharactId, ms) {