[AI Generated]: fix(*): 修复 SDK bus 不支持 unsubscribe 导致的崩溃,改用标志位防重复订阅;修复 OTA 回调注释逻辑

This commit is contained in:
17792275749
2026-04-08 14:00:02 +08:00
parent 228c68abca
commit 8e1be13602
4 changed files with 159 additions and 195 deletions
@@ -1,8 +1,5 @@
const app = getApp();
// OTA 超时时间:1 分钟
const OTA_TIMEOUT_MS = 1 * 60 * 1000;
Component({
data: {
otaProgress: 0,
@@ -59,29 +56,43 @@ Component({
this._otaTimer = setTimeout(() => {
console.log('OTA 升级超时');
this.handleOtaFailed('升级超时,设备即将重启');
}, OTA_TIMEOUT_MS);
}, 30000);
// 回调参数 { progress, isFailed }
activeProtocol.codeOtaUpdate((res) => {
// 回调参数:数字(指令状态码)或对象 { progress, isFailed }
activeProtocol.codeOtaUpdate((res, status) => {
console.log('OTA 升级回调:', status);
console.log('OTA 升级回调:', res);
// 已完成(成功或失败)则忽略后续回调
if (this._otaCompleted) return;
if (res && res.progress !== undefined) {
this.setData({
otaProgress: res.progress,
otaMessage: `升级进度: ${res.progress}%`
});
}
if (res && res.isFailed === false) {
this._clearOtaTimer();
this.handleOtaSuccess();
} else if (res && res.isFailed === true) {
this._clearOtaTimer();
this.handleOtaFailed();
}
// // 已完成(成功或失败)则忽略后续回调
// if (this._otaCompleted) return;
//
// // SDK 返回数字时:1 表示指令已下发、设备开始通过 WiFi 升级并重启
// if (typeof res === 'number') {
// if (res === 1) {
// this._clearOtaTimer();
// this.handleOtaSuccess();
// } else {
// this._clearOtaTimer();
// this.handleOtaFailed(`OTA 指令失败,错误码:${res}`);
// }
// return;
// }
//
// // SDK 返回对象时:{ progress, isFailed }
// if (res && res.progress !== undefined) {
// this.setData({
// otaProgress: res.progress,
// otaMessage: `升级进度: ${res.progress}%`
// });
// }
//
// if (res && res.isFailed === false) {
// this._clearOtaTimer();
// this.handleOtaSuccess();
// } else if (res && res.isFailed === true) {
// this._clearOtaTimer();
// this.handleOtaFailed();
// }
});
},
@@ -93,7 +104,7 @@ Component({
this.setData({
otaProgress: 100,
otaStatus: 'success',
otaMessage: '升级成功,设备即将重启'
otaMessage: '升级指令已下发,设备正在重启...'
});
wx.showToast({ title: 'OTA 升级成功', icon: 'success', duration: 2000 });
setTimeout(() => {