fix(equipment): 回前台自动重连后同步设备连接状态

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
17792275749
2026-08-25 21:11:42 +08:00
co-authored by Claude Opus 4.7
parent e95d28a87b
commit f3f4d56ceb
+17 -1
View File
@@ -53,6 +53,7 @@ interface DeviceItem {
let unsubDevicesList: (() => void) | null = null let unsubDevicesList: (() => void) | null = null
let unsubConnect: (() => void) | null = null let unsubConnect: (() => void) | null = null
let unsubDisconnected: (() => void) | null = null let unsubDisconnected: (() => void) | null = null
let unsubDeviceConnect: (() => void) | null = null
let scanTimer: number | null = null let scanTimer: number | null = null
Page({ Page({
@@ -68,18 +69,23 @@ Page({
this.setData({ operationsEngineer: getApp<IAppOption>().globalData.operationsEngineer ?? false }) this.setData({ operationsEngineer: getApp<IAppOption>().globalData.operationsEngineer ?? false })
this.loadDevices() this.loadDevices()
this._subscribeDisconnected() this._subscribeDisconnected()
this._subscribeDeviceConnect()
}, },
onHide() { onHide() {
leFuService.stopScan() leFuService.stopScan()
unsubDisconnected?.() unsubDisconnected?.()
unsubDisconnected = null unsubDisconnected = null
unsubDeviceConnect?.()
unsubDeviceConnect = null
}, },
onUnload() { onUnload() {
leFuService.stopScan() leFuService.stopScan()
unsubDisconnected?.() unsubDisconnected?.()
unsubDisconnected = null unsubDisconnected = null
unsubDeviceConnect?.()
unsubDeviceConnect = null
unsubDevicesList?.() unsubDevicesList?.()
unsubDevicesList = null unsubDevicesList = null
unsubConnect?.() unsubConnect?.()
@@ -97,6 +103,17 @@ Page({
}) })
}, },
/** 订阅连接成功事件:回前台自动重连等场景下,同步页面状态为已连接 */
_subscribeDeviceConnect() {
unsubDeviceConnect?.()
unsubDeviceConnect = leFuService.onDeviceConnect(() => {
const deviceId = leFuService.lastRawDevice?.deviceId ?? ''
if (deviceId) {
this._updateStatus(deviceId, true)
}
})
},
/** 拉取体重设备列表 */ /** 拉取体重设备列表 */
async loadDevices() { async loadDevices() {
const raw = wx.getStorageSync('userInfo') as UserInfo | null const raw = wx.getStorageSync('userInfo') as UserInfo | null
@@ -203,7 +220,6 @@ Page({
unsubConnect = null unsubConnect = null
wx.hideLoading() wx.hideLoading()
wx.setStorageSync('connectDeviceInfo', matched.raw) wx.setStorageSync('connectDeviceInfo', matched.raw)
this._updateStatus(targetDeviceId, true)
}) })
}) })
leFuService.startScan() leFuService.startScan()