[AI Generated]: feat(*): 新增 autoConnect 自动重连机制、OTA 断连兜底触发,修复 diff 为零时颜色与箭头展示异常

This commit is contained in:
17792275749
2026-05-18 10:11:41 +08:00
parent 64029c80b1
commit 4b1ff061fa
8 changed files with 63 additions and 48 deletions
+5 -35
View File
@@ -93,49 +93,19 @@ Page({
})
},
/** 检查缓存设备:已连接则直接标记,未连接则扫描匹配 deviceId 后自动连接 */
/** 检查缓存设备:已连接则直接标记,未连接则调 autoConnect 扫描重连 */
_checkAndAutoConnect() {
const cachedRaw = wx.getStorageSync('connectDeviceInfo') as RawDevice | null
const targetDeviceId = cachedRaw?.deviceId as string | undefined
if (!targetDeviceId) return
// 已连接且 deviceInfo 就绪,直接标记列表
if (lefuService.isConnected && lefuService.deviceInfo?.serialNumber) {
this._markConnected(lefuService.deviceInfo.serialNumber as string)
return
}
let scanTimer: number | null = null
wx.showLoading({ title: '连接中...', mask: true })
wx.openBluetoothAdapter({
success: () => {
scanTimer = setTimeout(() => {
lefuService.stopScan()
wx.hideLoading()
}, 15000)
lefuService.onDevicesList((devices) => {
const matched = devices.find(d => d.raw.deviceId === targetDeviceId)
if (!matched) return
if (scanTimer !== null) { clearTimeout(scanTimer); scanTimer = null }
lefuService.stopScan()
lefuService.connect(matched.raw)
lefuService.onDeviceConnect(() => {
wx.hideLoading()
wx.setStorageSync('connectDeviceInfo', matched.raw)
})
lefuService.onDeviceInfo((info) => {
this._markConnected(info.serialNumber as string)
})
})
lefuService.startScan()
},
fail: () => {
if (scanTimer !== null) { clearTimeout(scanTimer); scanTimer = null }
wx.hideLoading()
},
// 注册回调:连接成功后更新列表状态
lefuService.onDeviceInfo((info) => {
this._markConnected(info.serialNumber as string)
})
lefuService.autoConnect()
},
/** 将 serialNumber 对应的列表项标记为已连接,其余置为未连接 */