fix: 修复wifi页面连接超时问题

This commit is contained in:
2026-07-01 15:54:58 +08:00
parent 40b94dbad8
commit 8b7a94b8c4
+17 -5
View File
@@ -52,7 +52,7 @@ let wifiConnectTimer = null;
let wifiConnectRequestId = 0; let wifiConnectRequestId = 0;
let wifiConnectPollCount = 0; let wifiConnectPollCount = 0;
const WIFI_CONNECT_POLL_INTERVAL = 2000; 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 WIFI_CONNECT_FAILED_TEXT = "连接失败,请检查WiFi密码或WiFi状态";
const OTA_MIN_BATTERY = 20; const OTA_MIN_BATTERY = 20;
const OTA_LOW_BATTERY_TEXT = "电量不足 50%,暂不支持 OTA 升级"; const OTA_LOW_BATTERY_TEXT = "电量不足 50%,暂不支持 OTA 升级";
@@ -273,12 +273,15 @@ const cancelWifiConnectPolling = () => {
uni.hideLoading(); uni.hideLoading();
}; };
// 判断设备是否已经在线且连接到 WiFi // 判断设备在线且已连 WiFionline:true + netType:"4g" 表示设备已切网但 WiFi 连接失败
const isDeviceConnectedByWifi = (deviceStatus) => { 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) => { const waitForDeviceWifiConnected = (requestId) => {
return new Promise((resolve) => { return new Promise((resolve) => {
const poll = async () => { const poll = async () => {
@@ -294,10 +297,19 @@ const waitForDeviceWifiConnected = (requestId) => {
resolve(false); resolve(false);
return; return;
} }
if (isDeviceConnectedByWifi(deviceStatus)) { const connResult = isDeviceConnectedByWifi(deviceStatus);
// online:true + netType:wifi → 成功
if (connResult === true) {
resolve(true); resolve(true);
return; return;
} }
// online:true + netType:4g → 立即失败(设备已切 4g,WiFi 连不上)
if (connResult === "net_fail") {
resolve(false);
return;
}
// online:false + netType:"" → 继续轮询
// online:true + netType:"" → 忽略,继续轮询(netType 暂未上报)
} catch (err) { } catch (err) {
if (requestId !== wifiConnectRequestId) { if (requestId !== wifiConnectRequestId) {
resolve(false); resolve(false);