[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
+33 -5
View File
@@ -20,8 +20,8 @@ const plugin = requirePlugin('ppScale-plugin') as LeFuPlugin
const LEFU_CONFIG: LeFuConfig = {
key: 'lefudc91611833e18d94',
secret: 'eQ50JYimMp0X7uhNLj6D3lTEk4TUUvEG7dvaqKM9t1U=',
domain1: 'http://192.168.1.207:8889',
domain2: 'http://192.168.1.207:8889/weight',
domain1: 'http://10.10.10.10:8889',
domain2: 'http://10.10.10.10:8889/weight',
// domain1: 'http://device.shuziweidao.com:80/gateway',
// domain2: 'http://device.shuziweidao.com:80/weight',
}
@@ -200,8 +200,6 @@ class LeFuService {
this._activeProtocol = null
this._connectState = ''
this._deviceInfo = null
this._onDeviceInfoCb = null
this._onDeviceConnectCb = null
// 直连缓存设备时不走 startScan,需手动初始化插件设备配置和总线订阅
plugin.Blue.setDeviceSetting(DEVICE_SETTINGS)
this._subscribeBus()
@@ -217,12 +215,42 @@ class LeFuService {
plugin.Blue.disconnect()
}
/** 读缓存设备信息,自动扫描匹配后连接,已连接或无缓存时直接返回 */
autoConnect(): void {
if (this.isConnected) return
const cached = wx.getStorageSync('connectDeviceInfo') as RawDevice | null
const targetDeviceId = cached?.deviceId as string | undefined
if (!targetDeviceId) return
let scanTimer: number | null = null
wx.openBluetoothAdapter({
success: () => {
scanTimer = setTimeout(() => {
this.stopScan()
}, 15000)
this.onDevicesList((devices) => {
const matched = devices.find(d => d.raw.deviceId === targetDeviceId)
if (!matched) return
if (scanTimer !== null) { clearTimeout(scanTimer); scanTimer = null }
this.stopScan()
wx.setStorageSync('connectDeviceInfo', matched.raw)
this.connect(matched.raw)
})
this.startScan()
},
fail: () => {
if (scanTimer !== null) { clearTimeout(scanTimer); scanTimer = null }
},
})
}
stopScan(): void {
console.log(TAG, 'stopScan()')
this._stopReconnectTimer()
wx.stopBluetoothDevicesDiscovery()
this._onDevicesListCb = null
this._onDeviceConnectCb = null
}
// ─── WiFi 配网 ────────────────────────────────