[AI Generated]: feat(home): 新增设备固件 OTA 自动检测与强制升级,页面生命周期内仅触发一次

This commit is contained in:
17792275749
2026-05-18 09:51:47 +08:00
parent 49b356335e
commit 64029c80b1
+28
View File
@@ -57,6 +57,8 @@ const splitWeight = (weight: number): { int: number; decimal: string } => {
} }
Page({ Page({
_otaChecked: false as boolean,
data: { data: {
hasData: false, hasData: false,
device: { device: {
@@ -72,6 +74,7 @@ Page({
}) })
lefuService.onDeviceConnect(() => { lefuService.onDeviceConnect(() => {
this.setData({ 'device.connected': true }) this.setData({ 'device.connected': true })
this._checkOta()
}) })
lefuService.onDisconnected(() => { lefuService.onDisconnected(() => {
this.setData({ 'device.connected': false }) this.setData({ 'device.connected': false })
@@ -137,6 +140,31 @@ Page({
}) })
}, },
/** OTA 固件检测,连接成功后自动调用,有新版本直接升级,整个页面生命周期只触发一次 */
_checkOta() {
if (this._otaChecked) return
this._otaChecked = true
lefuService.checkAndUpgrade()
.then(needUpdate => {
if (!needUpdate) return
wx.showLoading({ title: '固件升级中...', mask: true })
lefuService.checkAndUpgrade()
.then(() => {
wx.hideLoading()
wx.showModal({
title: '升级完成',
content: '固件升级成功,请重新开启设备',
showCancel: false,
})
})
.catch((err: Error) => {
wx.hideLoading()
wx.showToast({ title: err.message || '升级失败,请重试', icon: 'none' })
})
})
.catch(() => {})
},
/** 跳转历史数据页 */ /** 跳转历史数据页 */
onTapHistory() { onTapHistory() {
wx.switchTab({ url: '/pages/data/data' }) wx.switchTab({ url: '/pages/data/data' })