From 507915f2c48c3943a7662f66ec36888f8bceb9ca Mon Sep 17 00:00:00 2001 From: 17792275749 <812100002@qq.com> Date: Thu, 3 Sep 2026 17:29:49 +0800 Subject: [PATCH] =?UTF-8?q?fix(lefu):=20=E6=90=9C=E7=B4=A2=E6=97=B6=20UNAV?= =?UTF-8?q?AILABLE=20=E6=8A=96=E5=8A=A8=E4=B8=8D=E5=86=8D=E6=B8=85?= =?UTF-8?q?=E7=A9=BA=E5=8D=8F=E8=AE=AE=EF=BC=8C=E4=BF=AE=E5=A4=8D=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=90=8E=E8=AE=BE=E5=A4=87=E8=AF=AF=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E5=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.7 --- miniprogram/lefu/service.ts | 13 +++++++++++-- miniprogram/pages/equipment/equipment.ts | 9 +++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/miniprogram/lefu/service.ts b/miniprogram/lefu/service.ts index b4e0dcc..ed1facb 100644 --- a/miniprogram/lefu/service.ts +++ b/miniprogram/lefu/service.ts @@ -187,10 +187,17 @@ class LeFuService { this._doReconnect() return } - // 蓝牙不可用:做完整清理 + // 蓝牙不可用:蓝牙真关了才清空协议;扫描/连接期间的 UNAVAILABLE 抖动(蓝牙还开着)保留协议 if (res === plugin.BLUE_STATE.UNAVAILABLE) { + let bluetoothOff = false + try { bluetoothOff = wx.getSystemSetting().bluetoothEnabled === false } catch (e) { bluetoothOff = false } + console.log(TAG, 'UNAVAILABLE 排查', { intentionalConnect: this._intentionalConnect, hasProtocol: !!this._activeProtocol, bluetoothOff }) this._stopKeepAlive() this._stopReconnectTimer() + // 蓝牙还开着:只是抖动,保留协议,避免 isConnected 误判为 false + if (!bluetoothOff) { + return + } if (this._activeProtocol) { this._activeProtocol = null this._onDisconnectedCbs.forEach(cb => cb()) @@ -220,7 +227,9 @@ class LeFuService { // 即将断开:清理协议实例,若非主动断开则触发重连 plugin.bus.subscribe('deviceWillDisconnect', () => { - console.warn(TAG, 'bus[deviceWillDisconnect],intentionalConnect:', this._intentionalConnect) + let bluetoothEnabled = '' + try { bluetoothEnabled = String(wx.getSystemSetting().bluetoothEnabled) } catch (e) { bluetoothEnabled = 'unknown' } + console.warn(TAG, 'deviceWillDisconnect 排查', { intentionalConnect: this._intentionalConnect, hasProtocol: !!this._activeProtocol, bluetoothEnabled }) this._stopKeepAlive() if (this._activeProtocol) { this._activeProtocol = null diff --git a/miniprogram/pages/equipment/equipment.ts b/miniprogram/pages/equipment/equipment.ts index 47624f9..0832b2d 100644 --- a/miniprogram/pages/equipment/equipment.ts +++ b/miniprogram/pages/equipment/equipment.ts @@ -131,11 +131,16 @@ Page({ try { info = JSON.parse(item.connectDeviceInfo || '{}') } catch {} + const isConnected = leFuService.isConnected + const lastDeviceId = leFuService.lastRawDevice?.deviceId ?? '' + const infoDeviceId = info.deviceId ?? '' + const status = isConnected && lastDeviceId === infoDeviceId + console.log('[equipment] loadDevices 设备状态', { name: info.name, isConnected, lastDeviceId, infoDeviceId, status }) return { id: item.id, name: info.name ?? '', - status: leFuService.isConnected && leFuService.lastRawDevice?.deviceId === info.deviceId, - deviceId: info.deviceId ?? '', + status, + deviceId: infoDeviceId, sn: item.scaleDeviceId, userNum: item.userNum ?? 0, connectDeviceInfo: item.connectDeviceInfo ?? '',