From 8cb7a11fbe355d1e39c67d82196f96633b90a8df Mon Sep 17 00:00:00 2001 From: 17792275749 <812100002@qq.com> Date: Thu, 9 Apr 2026 10:53:53 +0800 Subject: [PATCH] =?UTF-8?q?[AI=20Generated]:=20fix(Comp):=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=20SDK=20=E8=B6=85=E6=97=B6=E5=8F=96=E6=B6=88=E6=9C=BA?= =?UTF-8?q?=E5=88=B6=EF=BC=8C=E7=BB=84=E4=BB=B6=E9=94=80=E6=AF=81=E6=97=B6?= =?UTF-8?q?=E6=B8=85=E9=99=A4=E5=AE=9A=E6=97=B6=E5=99=A8=E9=98=B2=E6=AD=A2?= =?UTF-8?q?=E6=AE=8B=E7=95=99=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 6 ++++++ components/configureDevice_2/configureDevice_2.js | 10 +++++----- components/configureDevice_3/configureDevice_3.js | 7 ++++--- components/replaceNetwork_3/replaceNetwork_3.js | 6 +++--- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/app.js b/app.js index 133b06c..2ed92c9 100644 --- a/app.js +++ b/app.js @@ -351,5 +351,11 @@ App({ clearTimeout(timer); onResult(res); }); + // 返回取消函数,供组件/页面在销毁时调用,静默取消超时 + return () => { + if (settled) return; + settled = true; + clearTimeout(timer); + }; }, }) \ No newline at end of file diff --git a/components/configureDevice_2/configureDevice_2.js b/components/configureDevice_2/configureDevice_2.js index 43082f6..1e8c570 100644 --- a/components/configureDevice_2/configureDevice_2.js +++ b/components/configureDevice_2/configureDevice_2.js @@ -53,10 +53,10 @@ Component({ this.fetchUserList(); }, detached() { - // 4. 在组件销毁时取消监听,防止内存泄漏 if (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 }); - app.callWithTimeout( + this._sdkCancel = app.callWithTimeout( (done) => app.globalData.ppScale.activeProtocol.dataFetchUserID(done), SDK_TIMEOUT, (deviceUserIds) => { @@ -243,7 +243,7 @@ Component({ } wx.showLoading({ title: "正在下发第" + (syncIndex + 1) + "/" + needSyncList.length + "个用户...", mask: true }); let user = needSyncList[syncIndex]; - app.callWithTimeout( + this._sdkCancel = app.callWithTimeout( (done) => app.globalData.ppScale.activeProtocol.dataSyncUserInfo({ userID: user.userId, userName: user.realname, @@ -290,7 +290,7 @@ Component({ } wx.showLoading({ title: "正在删除第" + (delIndex + 1) + "/" + needDeleteList.length + "个多余用户...", mask: true }); let item = needDeleteList[delIndex]; - app.callWithTimeout( + this._sdkCancel = app.callWithTimeout( (done) => app.globalData.ppScale.activeProtocol.dataDeleteUser({ userID: item.userID, memberID: "" @@ -330,7 +330,7 @@ Component({ */ _checkWifiAndNext() { wx.showLoading({ title: "正在检测配网状态...", mask: true }); - app.callWithTimeout( + this._sdkCancel = app.callWithTimeout( (done) => app.globalData.ppScale.activeProtocol.codeFetchWifiConfig(done), SDK_TIMEOUT, (res) => { diff --git a/components/configureDevice_3/configureDevice_3.js b/components/configureDevice_3/configureDevice_3.js index 817a785..54a0172 100644 --- a/components/configureDevice_3/configureDevice_3.js +++ b/components/configureDevice_3/configureDevice_3.js @@ -20,6 +20,7 @@ Component({ }, detached() { console.log('configureDevice3 detached'); + if (this._sdkCancel) { this._sdkCancel(); this._sdkCancel = null; } } }, @@ -34,7 +35,7 @@ Component({ wx.showToast({ title: '设备未连接,请重试', icon: 'none' }); return; } - app.callWithTimeout( + this._sdkCancel = app.callWithTimeout( (done) => activeProtocol.dataFindSurroundDevice(done), SDK_TIMEOUT, (res) => { @@ -83,7 +84,7 @@ Component({ let version = app.globalData.ppScale.version; if (version === 'domain1') { - app.callWithTimeout( + this._sdkCancel = app.callWithTimeout( (done) => app.globalData.ppScale.activeProtocol.dataConfigNetWork({ domain: app.globalData.ppScale.domain1, ssid: this.data.selectWifi.ssid, @@ -101,7 +102,7 @@ Component({ ); } if (version === 'domain2') { - app.callWithTimeout( + this._sdkCancel = app.callWithTimeout( (done) => app.globalData.ppScale.activeProtocol.dataConfigUserNetWork({ domain: app.globalData.ppScale.domain2, ssid: this.data.selectWifi.ssid, diff --git a/components/replaceNetwork_3/replaceNetwork_3.js b/components/replaceNetwork_3/replaceNetwork_3.js index 0a1c60c..c57571a 100644 --- a/components/replaceNetwork_3/replaceNetwork_3.js +++ b/components/replaceNetwork_3/replaceNetwork_3.js @@ -26,7 +26,7 @@ Component({ this.setNerwork(); }, detached() { - + if (this._sdkCancel) { this._sdkCancel(); this._sdkCancel = null; } } }, @@ -37,7 +37,7 @@ Component({ let password = this.properties.password; let version = app.globalData.ppScale.version; if (version === 'domain1') { - app.callWithTimeout( + this._sdkCancel = app.callWithTimeout( (done) => app.globalData.ppScale.activeProtocol.dataConfigNetWork({ domain: app.globalData.ppScale.domain1, ssid: ssid, @@ -57,7 +57,7 @@ Component({ ); } if (version === 'domain2') { - app.callWithTimeout( + this._sdkCancel = app.callWithTimeout( (done) => app.globalData.ppScale.activeProtocol.dataConfigUserNetWork({ domain: app.globalData.ppScale.domain2, ssid: ssid,