From 64029c80b134f95dffef15b8c884b85f6e5d06bf Mon Sep 17 00:00:00 2001 From: 17792275749 <812100002@qq.com> Date: Mon, 18 May 2026 09:51:47 +0800 Subject: [PATCH] =?UTF-8?q?[AI=20Generated]:=20feat(home):=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E8=AE=BE=E5=A4=87=E5=9B=BA=E4=BB=B6=20OTA=20=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=A3=80=E6=B5=8B=E4=B8=8E=E5=BC=BA=E5=88=B6=E5=8D=87?= =?UTF-8?q?=E7=BA=A7=EF=BC=8C=E9=A1=B5=E9=9D=A2=E7=94=9F=E5=91=BD=E5=91=A8?= =?UTF-8?q?=E6=9C=9F=E5=86=85=E4=BB=85=E8=A7=A6=E5=8F=91=E4=B8=80=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- miniprogram/pages/home/home.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/miniprogram/pages/home/home.ts b/miniprogram/pages/home/home.ts index b5b5c00..de55de1 100644 --- a/miniprogram/pages/home/home.ts +++ b/miniprogram/pages/home/home.ts @@ -57,6 +57,8 @@ const splitWeight = (weight: number): { int: number; decimal: string } => { } Page({ + _otaChecked: false as boolean, + data: { hasData: false, device: { @@ -72,6 +74,7 @@ Page({ }) lefuService.onDeviceConnect(() => { this.setData({ 'device.connected': true }) + this._checkOta() }) lefuService.onDisconnected(() => { 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() { wx.switchTab({ url: '/pages/data/data' })