fix(lefu): 完善蓝牙连接状态处理,修复断开后 UI 不同步问题
- connectState 回调增加 UNAVAILABLE 清理和 READY 自动重连 - disconnect() 增加 _intentionalConnect 标记避免误重连 - deviceWillDisconnect 增加 _activeProtocol 防重入判断 - connectedDevice/equipment/connectedWifi 增加断开状态响应 - connectedWifi 设备断开后自动退出配网页 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
15e089f5e3
commit
439f560218
@@ -25,7 +25,7 @@ Page({
|
||||
_toBleStatus(state: string): BleStatus {
|
||||
const bs = lefuService.BLUE_STATE
|
||||
if (state === bs.CONNECTSUCCESS || state === bs.WIFISUCCESS) return 'connected'
|
||||
if (state === bs.CONNECTFAILED) return 'failed'
|
||||
if (state === bs.CONNECTFAILED || state === bs.UNAVAILABLE) return 'failed'
|
||||
return 'connecting'
|
||||
},
|
||||
|
||||
@@ -34,6 +34,11 @@ Page({
|
||||
lefuService.onDeviceInfo((info) => {
|
||||
this.setData({ deviceName: info.modelNumber })
|
||||
})
|
||||
// 设备断开即退出配网页
|
||||
lefuService.onDisconnected(() => {
|
||||
wx.showToast({ title: '设备已断开连接', icon: 'none', duration: 1500 })
|
||||
setTimeout(() => wx.navigateBack(), 1500)
|
||||
})
|
||||
this.setData({
|
||||
bleStatus: this._toBleStatus(lefuService.connectState),
|
||||
deviceName: lefuService.deviceInfo?.modelNumber ?? '智能体重秤',
|
||||
@@ -43,15 +48,13 @@ Page({
|
||||
|
||||
onShow() {
|
||||
lefuService.onConnectState((state) => {
|
||||
const bs = lefuService.BLUE_STATE
|
||||
if (state === bs.CONNECTSUCCESS || state === bs.WIFISUCCESS || state === bs.CONNECTFAILED) {
|
||||
this.setData({ bleStatus: this._toBleStatus(state) })
|
||||
}
|
||||
this.setData({ bleStatus: this._toBleStatus(state) })
|
||||
})
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
wx.hideLoading()
|
||||
lefuService.onDisconnected(() => {})
|
||||
if (this.data.status === 'configuring') {
|
||||
lefuService.disconnect()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user