[AI Generated]: feat(Comp): 新增用户同步下发10秒超时保护机制
This commit is contained in:
@@ -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();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user