[AI Generated]: fix(Comp): 新增 SDK 超时取消机制,组件销毁时清除定时器防止残留提示
This commit is contained in:
@@ -351,5 +351,11 @@ App({
|
|||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
onResult(res);
|
onResult(res);
|
||||||
});
|
});
|
||||||
|
// 返回取消函数,供组件/页面在销毁时调用,静默取消超时
|
||||||
|
return () => {
|
||||||
|
if (settled) return;
|
||||||
|
settled = true;
|
||||||
|
clearTimeout(timer);
|
||||||
|
};
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -53,10 +53,10 @@ Component({
|
|||||||
this.fetchUserList();
|
this.fetchUserList();
|
||||||
},
|
},
|
||||||
detached() {
|
detached() {
|
||||||
// 4. 在组件销毁时取消监听,防止内存泄漏
|
|
||||||
if (this._connectStateWatcher) {
|
if (this._connectStateWatcher) {
|
||||||
app.unwatch('ppScale.device.connectState', this._connectStateWatcher);
|
app.unwatch('ppScale.device.connectState', this._connectStateWatcher);
|
||||||
}
|
}
|
||||||
|
if (this._sdkCancel) { this._sdkCancel(); this._sdkCancel = null; }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -190,7 +190,7 @@ Component({
|
|||||||
|
|
||||||
// 获取设备端已有用户,与用户列表做双向同步
|
// 获取设备端已有用户,与用户列表做双向同步
|
||||||
wx.showLoading({ title: "正在同步用户信息...", mask: true });
|
wx.showLoading({ title: "正在同步用户信息...", mask: true });
|
||||||
app.callWithTimeout(
|
this._sdkCancel = app.callWithTimeout(
|
||||||
(done) => app.globalData.ppScale.activeProtocol.dataFetchUserID(done),
|
(done) => app.globalData.ppScale.activeProtocol.dataFetchUserID(done),
|
||||||
SDK_TIMEOUT,
|
SDK_TIMEOUT,
|
||||||
(deviceUserIds) => {
|
(deviceUserIds) => {
|
||||||
@@ -243,7 +243,7 @@ Component({
|
|||||||
}
|
}
|
||||||
wx.showLoading({ title: "正在下发第" + (syncIndex + 1) + "/" + needSyncList.length + "个用户...", mask: true });
|
wx.showLoading({ title: "正在下发第" + (syncIndex + 1) + "/" + needSyncList.length + "个用户...", mask: true });
|
||||||
let user = needSyncList[syncIndex];
|
let user = needSyncList[syncIndex];
|
||||||
app.callWithTimeout(
|
this._sdkCancel = app.callWithTimeout(
|
||||||
(done) => app.globalData.ppScale.activeProtocol.dataSyncUserInfo({
|
(done) => app.globalData.ppScale.activeProtocol.dataSyncUserInfo({
|
||||||
userID: user.userId,
|
userID: user.userId,
|
||||||
userName: user.realname,
|
userName: user.realname,
|
||||||
@@ -290,7 +290,7 @@ Component({
|
|||||||
}
|
}
|
||||||
wx.showLoading({ title: "正在删除第" + (delIndex + 1) + "/" + needDeleteList.length + "个多余用户...", mask: true });
|
wx.showLoading({ title: "正在删除第" + (delIndex + 1) + "/" + needDeleteList.length + "个多余用户...", mask: true });
|
||||||
let item = needDeleteList[delIndex];
|
let item = needDeleteList[delIndex];
|
||||||
app.callWithTimeout(
|
this._sdkCancel = app.callWithTimeout(
|
||||||
(done) => app.globalData.ppScale.activeProtocol.dataDeleteUser({
|
(done) => app.globalData.ppScale.activeProtocol.dataDeleteUser({
|
||||||
userID: item.userID,
|
userID: item.userID,
|
||||||
memberID: ""
|
memberID: ""
|
||||||
@@ -330,7 +330,7 @@ Component({
|
|||||||
*/
|
*/
|
||||||
_checkWifiAndNext() {
|
_checkWifiAndNext() {
|
||||||
wx.showLoading({ title: "正在检测配网状态...", mask: true });
|
wx.showLoading({ title: "正在检测配网状态...", mask: true });
|
||||||
app.callWithTimeout(
|
this._sdkCancel = app.callWithTimeout(
|
||||||
(done) => app.globalData.ppScale.activeProtocol.codeFetchWifiConfig(done),
|
(done) => app.globalData.ppScale.activeProtocol.codeFetchWifiConfig(done),
|
||||||
SDK_TIMEOUT,
|
SDK_TIMEOUT,
|
||||||
(res) => {
|
(res) => {
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ Component({
|
|||||||
},
|
},
|
||||||
detached() {
|
detached() {
|
||||||
console.log('configureDevice3 detached');
|
console.log('configureDevice3 detached');
|
||||||
|
if (this._sdkCancel) { this._sdkCancel(); this._sdkCancel = null; }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -34,7 +35,7 @@ Component({
|
|||||||
wx.showToast({ title: '设备未连接,请重试', icon: 'none' });
|
wx.showToast({ title: '设备未连接,请重试', icon: 'none' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
app.callWithTimeout(
|
this._sdkCancel = app.callWithTimeout(
|
||||||
(done) => activeProtocol.dataFindSurroundDevice(done),
|
(done) => activeProtocol.dataFindSurroundDevice(done),
|
||||||
SDK_TIMEOUT,
|
SDK_TIMEOUT,
|
||||||
(res) => {
|
(res) => {
|
||||||
@@ -83,7 +84,7 @@ Component({
|
|||||||
|
|
||||||
let version = app.globalData.ppScale.version;
|
let version = app.globalData.ppScale.version;
|
||||||
if (version === 'domain1') {
|
if (version === 'domain1') {
|
||||||
app.callWithTimeout(
|
this._sdkCancel = app.callWithTimeout(
|
||||||
(done) => app.globalData.ppScale.activeProtocol.dataConfigNetWork({
|
(done) => app.globalData.ppScale.activeProtocol.dataConfigNetWork({
|
||||||
domain: app.globalData.ppScale.domain1,
|
domain: app.globalData.ppScale.domain1,
|
||||||
ssid: this.data.selectWifi.ssid,
|
ssid: this.data.selectWifi.ssid,
|
||||||
@@ -101,7 +102,7 @@ Component({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (version === 'domain2') {
|
if (version === 'domain2') {
|
||||||
app.callWithTimeout(
|
this._sdkCancel = app.callWithTimeout(
|
||||||
(done) => app.globalData.ppScale.activeProtocol.dataConfigUserNetWork({
|
(done) => app.globalData.ppScale.activeProtocol.dataConfigUserNetWork({
|
||||||
domain: app.globalData.ppScale.domain2,
|
domain: app.globalData.ppScale.domain2,
|
||||||
ssid: this.data.selectWifi.ssid,
|
ssid: this.data.selectWifi.ssid,
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ Component({
|
|||||||
this.setNerwork();
|
this.setNerwork();
|
||||||
},
|
},
|
||||||
detached() {
|
detached() {
|
||||||
|
if (this._sdkCancel) { this._sdkCancel(); this._sdkCancel = null; }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ Component({
|
|||||||
let password = this.properties.password;
|
let password = this.properties.password;
|
||||||
let version = app.globalData.ppScale.version;
|
let version = app.globalData.ppScale.version;
|
||||||
if (version === 'domain1') {
|
if (version === 'domain1') {
|
||||||
app.callWithTimeout(
|
this._sdkCancel = app.callWithTimeout(
|
||||||
(done) => app.globalData.ppScale.activeProtocol.dataConfigNetWork({
|
(done) => app.globalData.ppScale.activeProtocol.dataConfigNetWork({
|
||||||
domain: app.globalData.ppScale.domain1,
|
domain: app.globalData.ppScale.domain1,
|
||||||
ssid: ssid,
|
ssid: ssid,
|
||||||
@@ -57,7 +57,7 @@ Component({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (version === 'domain2') {
|
if (version === 'domain2') {
|
||||||
app.callWithTimeout(
|
this._sdkCancel = app.callWithTimeout(
|
||||||
(done) => app.globalData.ppScale.activeProtocol.dataConfigUserNetWork({
|
(done) => app.globalData.ppScale.activeProtocol.dataConfigUserNetWork({
|
||||||
domain: app.globalData.ppScale.domain2,
|
domain: app.globalData.ppScale.domain2,
|
||||||
ssid: ssid,
|
ssid: ssid,
|
||||||
|
|||||||
Reference in New Issue
Block a user