[AI Generated]: fix(lefu): 修复蓝牙断连后 isConnected 误报及重连无效问题,新增 equipmentMember 页 onShow 兜底注释

This commit is contained in:
17792275749
2026-05-18 09:30:36 +08:00
parent ce586bf6ae
commit 49b356335e
4 changed files with 19 additions and 6 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ClaudeCodeTabState"> <component name="ClaudeCodeTabState">
<option name="tabCount" value="3" /> <option name="tabCount" value="4" />
</component> </component>
</project> </project>
+10 -3
View File
@@ -83,6 +83,7 @@ class LeFuService {
private readonly _maxReconnect = 3 private readonly _maxReconnect = 3
private _reconnectTimer: number | null = null private _reconnectTimer: number | null = null
private _keepAliveTimer: number | null = null private _keepAliveTimer: number | null = null
private _lastRawDevice: RawDevice | null = null
private _onDevicesListCb: ((devices: ScannedDevice[]) => void) | null = null private _onDevicesListCb: ((devices: ScannedDevice[]) => void) | null = null
private _onConnectStateCb: ((state: string) => void) | null = null private _onConnectStateCb: ((state: string) => void) | null = null
@@ -181,6 +182,7 @@ class LeFuService {
plugin.bus.subscribe('deviceWillDisconnect', () => { plugin.bus.subscribe('deviceWillDisconnect', () => {
console.warn(TAG, 'bus[deviceWillDisconnect]intentionalConnect:', this._intentionalConnect) console.warn(TAG, 'bus[deviceWillDisconnect]intentionalConnect:', this._intentionalConnect)
this._activeProtocol = null
this._stopKeepAlive() this._stopKeepAlive()
this._onDisconnectedCb?.() this._onDisconnectedCb?.()
if (!this._intentionalConnect) { if (!this._intentionalConnect) {
@@ -191,6 +193,7 @@ class LeFuService {
connect(rawDevice: RawDevice): void { connect(rawDevice: RawDevice): void {
console.log(TAG, 'connect():', rawDevice.name) console.log(TAG, 'connect():', rawDevice.name)
this._lastRawDevice = rawDevice
this._intentionalConnect = true this._intentionalConnect = true
this._stopKeepAlive() this._stopKeepAlive()
this._stopReconnectTimer() this._stopReconnectTimer()
@@ -331,15 +334,19 @@ class LeFuService {
private _doReconnect(): void { private _doReconnect(): void {
if (this._reconnectCount >= this._maxReconnect) { if (this._reconnectCount >= this._maxReconnect) {
console.warn(TAG, '重连次数已达上限') console.warn(TAG, '重连次数已达上限')
this._onDisconnectedCb?.()
return
}
if (!this._lastRawDevice) {
console.warn(TAG, '无缓存设备,放弃重连')
return return
} }
this._reconnectCount++ this._reconnectCount++
console.log(TAG, `_doReconnect 第 ${this._reconnectCount}`) console.log(TAG, `_doReconnect 第 ${this._reconnectCount}`)
this._stopReconnectTimer() this._stopReconnectTimer()
this._reconnectTimer = setTimeout(() => { this._reconnectTimer = setTimeout(() => {
plugin.Blue.disconnect((res: any) => { plugin.Blue.clearProtocol()
if (res?.errCode === 0) plugin.Blue.startBluetoothDevicesDiscovery() plugin.Blue.createBLEConnection(this._lastRawDevice!)
})
}, 2000) }, 2000)
} }
@@ -130,6 +130,12 @@ Page({
memberList: [] as MemberDisplay[], memberList: [] as MemberDisplay[],
}, },
// 当前子页 addMember 未注册任何 SDK 回调,不会覆盖本页回调槽位,故无需 onShow 兜底。
// 若未来子页新增 onDeviceConnect / onDisconnected 注册,需启用以下 onShow 同步连接状态。
// onShow() {
// this.setData({ connected: lefuService.isConnected })
// },
onLoad() { onLoad() {
const deviceInfo = lefuService.deviceInfo const deviceInfo = lefuService.deviceInfo
this.setData({ this.setData({
+2 -2
View File
@@ -1,5 +1,5 @@
{ {
"libVersion": "2.32.3", "libVersion": "3.15.2",
"projectname": "bodyWeight", "projectname": "bodyWeight",
"setting": { "setting": {
"urlCheck": false, "urlCheck": false,
@@ -14,7 +14,7 @@
"useLanDebug": false, "useLanDebug": false,
"showES6CompileOption": false, "showES6CompileOption": false,
"compileHotReLoad": true, "compileHotReLoad": true,
"bigPackageSizeSupport": false, "bigPackageSizeSupport": true,
"checkInvalidKey": true, "checkInvalidKey": true,
"ignoreDevUnusedFiles": true "ignoreDevUnusedFiles": true
} }