[AI Generated]: refactor(*): 保活定时器与连接清理逻辑收口至 app.js,修复 null 安全与注释错误

- 新增 app.startKeepAlive/stopKeepAlive/cleanupConnection,bus 监听自动控制保活与断联清理
- Blue.stop() 收入 cleanupConnection,页面 onHide/onUnload 统一调用
- 修复 replaceNetwork.js seviceList 可能为 undefined 导致崩溃
- 修复 configureDevice_2.js device.mac 为 null 时崩溃
- 修复 replaceNetwork_1.js activeProtocol 无 null 检查及 wifiList 容错
- 修正 configureDevice_4.js 超时注释(3分钟→30秒)
This commit is contained in:
17792275749
2026-04-08 14:56:48 +08:00
parent 5096ceaa53
commit de8fa1fca8
7 changed files with 67 additions and 69 deletions
+7 -28
View File
@@ -59,7 +59,6 @@ Page({
const nameArr = this.data.device.name.split("-");
app.globalData.ppScale.version = nameArr.length === 5 ? "domain2" : "domain1";
wx.hideLoading();
this._startKeepAlive();
if (this.data.progress === 0) {
const comp = this.selectComponent('#replaceNetwork1Component');
if (comp) comp.getWiFiList();
@@ -193,6 +192,11 @@ Page({
let seviceList = app.globalData.ppScale.device.setting.find((item) => {
return item.deviceName === res.result[0].type
});
if (!seviceList) {
wx.hideLoading();
wx.showToast({ title: '未找到匹配的设备类型', icon: 'none' });
return;
}
app.globalData.ppScale.plugin.Blue.setDeviceSetting([seviceList]);
app.globalData.ppScale.plugin.Blue.start(res.result[0].type, false);
app.globalData.ppScale.plugin.bus.subscribe("devicesList", (res_) => {
@@ -262,39 +266,14 @@ Page({
}
},
// 启动保活定时器,每10秒发送一次保活指令
_keepAliveTimer: null,
_startKeepAlive() {
this._stopKeepAlive();
this._keepAliveTimer = setInterval(() => {
if (app.globalData.ppScale.activeProtocol) {
app.globalData.ppScale.activeProtocol.sendKeepAliveCode();
}
}, 15000);
},
// 清除保活定时器
_stopKeepAlive() {
if (this._keepAliveTimer) {
clearInterval(this._keepAliveTimer);
this._keepAliveTimer = null;
}
},
onHide() {
console.log("replaceNetwork onHide");
this._stopKeepAlive();
app.resetReconnectCount();
app.setGlobalData('ppScale.device.connectState', null);
app.globalData.ppScale.plugin.Blue.stop();
app.cleanupConnection();
},
onUnload() {
console.log("replaceNetwork onUnload");
this._stopKeepAlive();
app.resetReconnectCount();
app.setGlobalData('ppScale.device.connectState', null);
app.globalData.ppScale.plugin.Blue.stop();
app.cleanupConnection();
if (this._connectStateWatcher) {
app.unwatch('ppScale.device.connectState', this._connectStateWatcher);
}