[AI Generated]: feat(*): 新增配网状态检测与SDK超时保护,优化配置流程稳定性
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
const app = getApp();
|
||||
import $ from "../../utils/request";
|
||||
|
||||
// 超时时间:15 秒
|
||||
const SDK_TIMEOUT = 15000;
|
||||
|
||||
/**
|
||||
* 根据生日计算年龄
|
||||
* @param {string} birthday 生日字符串,如 "1990-05-20"
|
||||
@@ -187,7 +190,10 @@ Component({
|
||||
|
||||
// 获取设备端已有用户,与用户列表做双向同步
|
||||
wx.showLoading({ title: "正在同步用户信息...", mask: true });
|
||||
app.globalData.ppScale.activeProtocol.dataFetchUserID((deviceUserIds) => {
|
||||
app.callWithTimeout(
|
||||
(done) => app.globalData.ppScale.activeProtocol.dataFetchUserID(done),
|
||||
SDK_TIMEOUT,
|
||||
(deviceUserIds) => {
|
||||
console.log("设备端已有用户ID列表", deviceUserIds);
|
||||
|
||||
// 回调返回非数组视为获取失败
|
||||
@@ -211,7 +217,7 @@ Component({
|
||||
|
||||
// 秤没有、列表有 → 需要下发到秤
|
||||
let needSyncList = userList.filter(user => !deviceIds.some(d => d.userID === String(user.userId)));
|
||||
|
||||
|
||||
console.log("需删除", needDeleteList, "需下发", needSyncList);
|
||||
|
||||
// 无需操作时直接完成
|
||||
@@ -219,7 +225,7 @@ Component({
|
||||
wx.hideLoading();
|
||||
wx.showToast({ title: "用户信息已同步", icon: "success" });
|
||||
setTimeout(() => {
|
||||
this.triggerEvent('deviceEvent', { status: true });
|
||||
this._checkWifiAndNext();
|
||||
}, 1500);
|
||||
return;
|
||||
}
|
||||
@@ -237,29 +243,37 @@ Component({
|
||||
}
|
||||
wx.showLoading({ title: "正在下发第" + (syncIndex + 1) + "/" + needSyncList.length + "个用户...", mask: true });
|
||||
let user = needSyncList[syncIndex];
|
||||
app.globalData.ppScale.activeProtocol.dataSyncUserInfo({
|
||||
userID: user.userId,
|
||||
userName: user.realname,
|
||||
memberID: "",
|
||||
age: user.age || '',
|
||||
gender: user.sex === 2 ? 0 : user.sex,
|
||||
height: String(user.height || ''),
|
||||
isAthleteMode: 0,
|
||||
deviceHeaderIndex: syncIndex,
|
||||
currentWeight: String(user.weight || ''),
|
||||
targetWeight: "",
|
||||
idealWeight: "",
|
||||
recentData: [],
|
||||
}, (res) => {
|
||||
if (res == 0) {
|
||||
syncIndex++;
|
||||
syncNext();
|
||||
} else {
|
||||
app.callWithTimeout(
|
||||
(done) => app.globalData.ppScale.activeProtocol.dataSyncUserInfo({
|
||||
userID: user.userId,
|
||||
userName: user.realname,
|
||||
memberID: "",
|
||||
age: user.age || '',
|
||||
gender: user.sex === 2 ? 0 : user.sex,
|
||||
height: String(user.height || ''),
|
||||
isAthleteMode: 0,
|
||||
deviceHeaderIndex: syncIndex,
|
||||
currentWeight: String(user.weight || ''),
|
||||
targetWeight: "",
|
||||
idealWeight: "",
|
||||
recentData: [],
|
||||
}, done),
|
||||
SDK_TIMEOUT,
|
||||
(res) => {
|
||||
if (res == 0) {
|
||||
syncIndex++;
|
||||
syncNext();
|
||||
} else {
|
||||
wx.hideLoading();
|
||||
console.log("dataSyncUserInfo 失败", res);
|
||||
wx.showToast({ title: "用户信息下发失败,请重试。", icon: "none" });
|
||||
}
|
||||
},
|
||||
() => {
|
||||
wx.hideLoading();
|
||||
console.log("dataSyncUserInfo 失败", res);
|
||||
wx.showToast({ title: "用户信息下发失败,请重试。", icon: "none" });
|
||||
wx.showToast({ title: "用户下发超时,请重试", icon: "none" });
|
||||
}
|
||||
});
|
||||
);
|
||||
};
|
||||
|
||||
// 第二步:逐个删除秤端多余用户
|
||||
@@ -270,30 +284,66 @@ Component({
|
||||
wx.hideLoading();
|
||||
wx.showToast({ title: "用户信息同步成功", icon: "success" });
|
||||
setTimeout(() => {
|
||||
this.triggerEvent('deviceEvent', { status: true });
|
||||
this._checkWifiAndNext();
|
||||
}, 1500);
|
||||
return;
|
||||
}
|
||||
wx.showLoading({ title: "正在删除第" + (delIndex + 1) + "/" + needDeleteList.length + "个多余用户...", mask: true });
|
||||
let item = needDeleteList[delIndex];
|
||||
app.globalData.ppScale.activeProtocol.dataDeleteUser({
|
||||
userID: item.userID,
|
||||
memberID: ""
|
||||
}, (status) => {
|
||||
if (status == 0) {
|
||||
delIndex++;
|
||||
deleteNext();
|
||||
} else {
|
||||
app.callWithTimeout(
|
||||
(done) => app.globalData.ppScale.activeProtocol.dataDeleteUser({
|
||||
userID: item.userID,
|
||||
memberID: ""
|
||||
}, done),
|
||||
SDK_TIMEOUT,
|
||||
(status) => {
|
||||
if (status == 0) {
|
||||
delIndex++;
|
||||
deleteNext();
|
||||
} else {
|
||||
wx.hideLoading();
|
||||
console.log("dataDeleteUser 失败", status);
|
||||
wx.showToast({ title: "删除设备用户失败,请重试。", icon: "none" });
|
||||
}
|
||||
},
|
||||
() => {
|
||||
wx.hideLoading();
|
||||
console.log("dataDeleteUser 失败", status);
|
||||
wx.showToast({ title: "删除设备用户失败,请重试。", icon: "none" });
|
||||
wx.showToast({ title: "删除用户超时,请重试", icon: "none" });
|
||||
}
|
||||
});
|
||||
);
|
||||
};
|
||||
|
||||
// 从下发开始执行
|
||||
syncNext();
|
||||
});
|
||||
},
|
||||
() => {
|
||||
wx.hideLoading();
|
||||
wx.showToast({ title: "获取设备用户超时,请重试", icon: "none" });
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* 同步完成后检测配网状态,决定跳转到哪一步
|
||||
* 已配网(0x01) → progressIndex: 3,跳过配网步骤
|
||||
* 未配网 → progressIndex: 2,进入配网步骤
|
||||
*/
|
||||
_checkWifiAndNext() {
|
||||
wx.showLoading({ title: "正在检测配网状态...", mask: true });
|
||||
app.callWithTimeout(
|
||||
(done) => app.globalData.ppScale.activeProtocol.codeFetchWifiConfig(done),
|
||||
SDK_TIMEOUT,
|
||||
(res) => {
|
||||
wx.hideLoading();
|
||||
// 0x01 表示已配网,跳过配网步骤直接进入下一步
|
||||
const progressIndex = res === 0x01 ? 3 : 2;
|
||||
this.triggerEvent('deviceEvent', { status: true, progressIndex });
|
||||
},
|
||||
() => {
|
||||
wx.hideLoading();
|
||||
wx.showToast({ title: "检测配网状态超时,请重试。", icon: "none" });
|
||||
}
|
||||
);
|
||||
},
|
||||
}
|
||||
});
|
||||
@@ -1,5 +1,7 @@
|
||||
const app = getApp();
|
||||
import $ from "../../utils/request";
|
||||
|
||||
// 超时时间:15 秒
|
||||
const SDK_TIMEOUT = 15000;
|
||||
|
||||
Component({
|
||||
data: {
|
||||
@@ -32,10 +34,18 @@ Component({
|
||||
wx.showToast({ title: '设备未连接,请重试', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
activeProtocol.dataFindSurroundDevice((res) => {
|
||||
wx.hideLoading();
|
||||
this.setData({ wifiList: Array.isArray(res) ? res : [] });
|
||||
});
|
||||
app.callWithTimeout(
|
||||
(done) => activeProtocol.dataFindSurroundDevice(done),
|
||||
SDK_TIMEOUT,
|
||||
(res) => {
|
||||
wx.hideLoading();
|
||||
this.setData({ wifiList: Array.isArray(res) ? res : [] });
|
||||
},
|
||||
() => {
|
||||
wx.hideLoading();
|
||||
wx.showToast({ title: "获取Wi-Fi列表超时,请重试", icon: "none" });
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
// 最小化后重连,重置所有状态并重新获取 WiFi 列表
|
||||
@@ -69,34 +79,46 @@ Component({
|
||||
},
|
||||
|
||||
setWifiPWD() {
|
||||
this.setData({
|
||||
progress: 2
|
||||
})
|
||||
this.setData({ progress: 2 });
|
||||
|
||||
let version = app.globalData.ppScale.version;
|
||||
if (version === 'domain1') {
|
||||
app.globalData.ppScale.activeProtocol.dataConfigNetWork({
|
||||
domain: app.globalData.ppScale.domain1,
|
||||
ssid: this.data.selectWifi.ssid,
|
||||
password: this.data.selectWifiPWD
|
||||
}, (res) => {
|
||||
console.log("setNetwork.js dataConfigNetWork 1", res);
|
||||
|
||||
this.netWorkCallBack(res);
|
||||
})
|
||||
app.callWithTimeout(
|
||||
(done) => app.globalData.ppScale.activeProtocol.dataConfigNetWork({
|
||||
domain: app.globalData.ppScale.domain1,
|
||||
ssid: this.data.selectWifi.ssid,
|
||||
password: this.data.selectWifiPWD
|
||||
}, done),
|
||||
SDK_TIMEOUT,
|
||||
(res) => {
|
||||
console.log("setNetwork.js dataConfigNetWork 1", res);
|
||||
this.netWorkCallBack(res);
|
||||
},
|
||||
() => {
|
||||
this.setData({ progress: 1 });
|
||||
wx.showToast({ title: "配网超时,请重试", icon: "none" });
|
||||
}
|
||||
);
|
||||
}
|
||||
if (version === 'domain2') {
|
||||
app.globalData.ppScale.activeProtocol.dataConfigUserNetWork({
|
||||
domain: app.globalData.ppScale.domain2,
|
||||
ssid: this.data.selectWifi.ssid,
|
||||
password: this.data.selectWifiPWD,
|
||||
userName: "apiUser",
|
||||
userPassword: "3acebb95eb49577e9c2a2082589b9bd6",
|
||||
}, (res) => {
|
||||
console.log("setNetwork.js dataConfigUserNetWork 2", res);
|
||||
|
||||
this.netWorkCallBack(res);
|
||||
})
|
||||
app.callWithTimeout(
|
||||
(done) => app.globalData.ppScale.activeProtocol.dataConfigUserNetWork({
|
||||
domain: app.globalData.ppScale.domain2,
|
||||
ssid: this.data.selectWifi.ssid,
|
||||
password: this.data.selectWifiPWD,
|
||||
userName: "apiUser",
|
||||
userPassword: "3acebb95eb49577e9c2a2082589b9bd6",
|
||||
}, done),
|
||||
SDK_TIMEOUT,
|
||||
(res) => {
|
||||
console.log("setNetwork.js dataConfigUserNetWork 2", res);
|
||||
this.netWorkCallBack(res);
|
||||
},
|
||||
() => {
|
||||
this.setData({ progress: 1 });
|
||||
wx.showToast({ title: "配网超时,请重试", icon: "none" });
|
||||
}
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
const app = getApp();
|
||||
import $ from "../../utils/request";
|
||||
|
||||
// 超时时间:15 秒
|
||||
const SDK_TIMEOUT = 15000;
|
||||
|
||||
Component({
|
||||
properties: {
|
||||
ssid: {
|
||||
@@ -34,28 +37,46 @@ Component({
|
||||
let password = this.properties.password;
|
||||
let version = app.globalData.ppScale.version;
|
||||
if (version === 'domain1') {
|
||||
app.globalData.ppScale.activeProtocol.dataConfigNetWork({
|
||||
domain: app.globalData.ppScale.domain1,
|
||||
ssid: ssid,
|
||||
password: password
|
||||
}, (res) => {
|
||||
console.log("setNetwork.js dataConfigNetWork 1", res);
|
||||
|
||||
this.netWorkCallBack(res);
|
||||
})
|
||||
app.callWithTimeout(
|
||||
(done) => app.globalData.ppScale.activeProtocol.dataConfigNetWork({
|
||||
domain: app.globalData.ppScale.domain1,
|
||||
ssid: ssid,
|
||||
password: password
|
||||
}, done),
|
||||
SDK_TIMEOUT,
|
||||
(res) => {
|
||||
console.log("setNetwork.js dataConfigNetWork 1", res);
|
||||
this.netWorkCallBack(res);
|
||||
},
|
||||
() => {
|
||||
wx.showToast({ title: "配网超时,请重试", icon: "none" });
|
||||
setTimeout(() => {
|
||||
this.triggerEvent('wifiEvent', { status: false });
|
||||
}, 1500);
|
||||
}
|
||||
);
|
||||
}
|
||||
if (version === 'domain2') {
|
||||
app.globalData.ppScale.activeProtocol.dataConfigUserNetWork({
|
||||
domain: app.globalData.ppScale.domain2,
|
||||
ssid: ssid,
|
||||
password: password,
|
||||
userName: "apiUser",
|
||||
userPassword: "3acebb95eb49577e9c2a2082589b9bd6"
|
||||
}, (res) => {
|
||||
console.log("setNetwork.js dataConfigUserNetWork 2", res);
|
||||
|
||||
this.netWorkCallBack(res);
|
||||
})
|
||||
app.callWithTimeout(
|
||||
(done) => app.globalData.ppScale.activeProtocol.dataConfigUserNetWork({
|
||||
domain: app.globalData.ppScale.domain2,
|
||||
ssid: ssid,
|
||||
password: password,
|
||||
userName: "apiUser",
|
||||
userPassword: "3acebb95eb49577e9c2a2082589b9bd6"
|
||||
}, done),
|
||||
SDK_TIMEOUT,
|
||||
(res) => {
|
||||
console.log("setNetwork.js dataConfigUserNetWork 2", res);
|
||||
this.netWorkCallBack(res);
|
||||
},
|
||||
() => {
|
||||
wx.showToast({ title: "配网超时,请重试", icon: "none" });
|
||||
setTimeout(() => {
|
||||
this.triggerEvent('wifiEvent', { status: false });
|
||||
}, 1500);
|
||||
}
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user