fix: 修复wifi页面连接超时问题
This commit is contained in:
+17
-5
@@ -52,7 +52,7 @@ let wifiConnectTimer = null;
|
||||
let wifiConnectRequestId = 0;
|
||||
let wifiConnectPollCount = 0;
|
||||
const WIFI_CONNECT_POLL_INTERVAL = 2000;
|
||||
const WIFI_CONNECT_MAX_POLL_COUNT = 15;
|
||||
const WIFI_CONNECT_MAX_POLL_COUNT = 30;
|
||||
const WIFI_CONNECT_FAILED_TEXT = "连接失败,请检查WiFi密码或WiFi状态";
|
||||
const OTA_MIN_BATTERY = 20;
|
||||
const OTA_LOW_BATTERY_TEXT = "电量不足 50%,暂不支持 OTA 升级";
|
||||
@@ -273,12 +273,15 @@ const cancelWifiConnectPolling = () => {
|
||||
uni.hideLoading();
|
||||
};
|
||||
|
||||
// 判断设备是否已经在线且连接到 WiFi。
|
||||
// 判断设备在线且已连 WiFi;online:true + netType:"4g" 表示设备已切网但 WiFi 连接失败。
|
||||
const isDeviceConnectedByWifi = (deviceStatus) => {
|
||||
return deviceStatus?.online === true && String(deviceStatus?.netType || "").toLowerCase() === "wifi";
|
||||
if (deviceStatus?.online !== true) return false;
|
||||
const netType = String(deviceStatus?.netType || "").toLowerCase();
|
||||
if (netType === "4g") return "net_fail";
|
||||
return netType === "wifi";
|
||||
};
|
||||
|
||||
// 轮询设备电量接口,确认设备已经切换到 WiFi 在线状态。
|
||||
// 轮询设备电量接口,等待设备切到 WiFi 在线;netType:4g 快速失败,超时 30 次后放弃。
|
||||
const waitForDeviceWifiConnected = (requestId) => {
|
||||
return new Promise((resolve) => {
|
||||
const poll = async () => {
|
||||
@@ -294,10 +297,19 @@ const waitForDeviceWifiConnected = (requestId) => {
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
if (isDeviceConnectedByWifi(deviceStatus)) {
|
||||
const connResult = isDeviceConnectedByWifi(deviceStatus);
|
||||
// online:true + netType:wifi → 成功
|
||||
if (connResult === true) {
|
||||
resolve(true);
|
||||
return;
|
||||
}
|
||||
// online:true + netType:4g → 立即失败(设备已切 4g,WiFi 连不上)
|
||||
if (connResult === "net_fail") {
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
// online:false + netType:"" → 继续轮询
|
||||
// online:true + netType:"" → 忽略,继续轮询(netType 暂未上报)
|
||||
} catch (err) {
|
||||
if (requestId !== wifiConnectRequestId) {
|
||||
resolve(false);
|
||||
|
||||
Reference in New Issue
Block a user