From 5ec3b1c84b82a485b759186456de67752f1844f5 Mon Sep 17 00:00:00 2001 From: 17792275749 <812100002@qq.com> Date: Wed, 15 Apr 2026 09:20:38 +0800 Subject: [PATCH] =?UTF-8?q?[AI=20Generated]:=20feat(Comp):=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E7=94=A8=E6=88=B7=E5=90=8C=E6=AD=A5=E4=B8=8B=E5=8F=91?= =?UTF-8?q?10=E7=A7=92=E8=B6=85=E6=97=B6=E4=BF=9D=E6=8A=A4=E6=9C=BA?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../configureDevice_2/configureDevice_2.js | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/components/configureDevice_2/configureDevice_2.js b/components/configureDevice_2/configureDevice_2.js index b441f43..dea5b08 100644 --- a/components/configureDevice_2/configureDevice_2.js +++ b/components/configureDevice_2/configureDevice_2.js @@ -218,8 +218,30 @@ Component({ // 第二步:全量下发本地用户列表 let syncIndex = 0; + let syncTimer = null; + + // 清除超时定时器 + const clearSyncTimer = () => { + if (syncTimer) { + clearTimeout(syncTimer); + syncTimer = null; + } + }; + + // 重置超时定时器,10秒无响应则认定失败 + const resetSyncTimer = () => { + clearSyncTimer(); + syncTimer = setTimeout(() => { + console.log("dataSyncUserInfo 超时,第" + (syncIndex + 1) + "个用户下发超时"); + wx.hideLoading(); + wx.showToast({ title: "用户信息下发超时,请重试", icon: "none" }); + }, 15000); + }; + const syncNext = () => { if (syncIndex >= userList.length) { + // 全部下发完成,清除定时器 + clearSyncTimer(); wx.hideLoading(); wx.showToast({ title: "用户信息同步成功", icon: "success" }); setTimeout(() => { @@ -231,6 +253,8 @@ Component({ // 主用户 memberID 为空,子用户 memberID 为子用户自己的 userId const memberID = user.userId === mainUserId ? "" : user.userId; wx.showLoading({ title: "正在下发第" + (syncIndex + 1) + "/" + userList.length + "个用户...", mask: true }); + // 每次下发前重置10秒超时定时器 + resetSyncTimer(); app.globalData.ppScale.activeProtocol.dataSyncUserInfo({ userID: mainUserId, userName: user.realname, @@ -247,13 +271,13 @@ Component({ }, (res) => { console.log("dataSyncUserInfo res", res, "user:", user.realname, "userID:", mainUserId, "memberID:", memberID); if (res == 0) { + // 成功:重置定时器,继续下发下一个用户 + resetSyncTimer(); syncIndex++; syncNext(); } else { - // wx.hideLoading(); - // wx.showToast({ title: "用户信息下发失败,请重试。", icon: "none" }); - - // 失败自动重试当前用户 + // 失败自动重试当前用户,重置定时器 + resetSyncTimer(); syncNext(); } });