fix(lefu): 搜索时 UNAVAILABLE 抖动不再清空协议,修复返回后设备误判断开

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
17792275749
2026-09-03 17:29:49 +08:00
co-authored by Claude Opus 4.7
parent 97bf4674c0
commit 507915f2c4
2 changed files with 18 additions and 4 deletions
+11 -2
View File
@@ -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
+7 -2
View File
@@ -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 ?? '',