feat: OTA 首页弹窗优化

This commit is contained in:
2026-08-18 10:30:16 +08:00
parent 6c55d32f90
commit 9e6ad4cf50
+45 -13
View File
@@ -1,5 +1,5 @@
<script setup>
import {onMounted, onUnmounted, ref} from "vue";
import {onMounted, onUnmounted, ref, watch} from "vue";
import {onShareAppMessage, onShareTimeline, onShow} from "@dcloudio/uni-app";
import Container from "@/components/Container.vue";
import AppFooter from "@/components/AppFooter.vue";
@@ -52,6 +52,8 @@ const otaInfo = ref({
forceUpdate: false,
});
const isStartingOta = ref(false);
let isCheckingOta = false;
let otaCheckQueuedForOnline = false;
let otaProgressTimer = null;
let otaStatusTimer = null;
let otaTimeoutTimer = null;
@@ -91,21 +93,51 @@ const applyOtaVersionInfo = (versionInfo) => {
// 检查当前设备盒子是否存在可升级版本。
const checkOtaUpdate = async () => {
let versionInfo;
if (isCheckingOta || otaVisible.value) return;
isCheckingOta = true;
try {
versionInfo = await getHardwareBoxVersionAPI();
} catch (err) {
let deviceStatus;
try {
deviceStatus = await getDeviceBatteryAPI();
} catch (err) {
return;
}
if (deviceStatus?.online !== true || otaVisible.value) return;
let versionInfo;
try {
versionInfo = await getHardwareBoxVersionAPI();
} catch (err) {
return;
}
if (!versionInfo?.needUpdate || otaVisible.value) return;
applyOtaVersionInfo(versionInfo);
const dismissedAt = uni.getStorageSync("ota_dismissed_at");
const now = Date.now();
if (!otaInfo.value.forceUpdate && dismissedAt && now - dismissedAt < 24 * 60 * 60 * 1000) return;
otaState.value = "new_version";
otaVisible.value = true;
} finally {
isCheckingOta = false;
const shouldRecheckForOnline = otaCheckQueuedForOnline;
otaCheckQueuedForOnline = false;
if (shouldRecheckForOnline && !otaVisible.value) {
void checkOtaUpdate();
}
}
};
// 设备由 WS 通知上线时补查 OTA;已显示任何 OTA 弹窗时保留当前流程和结果。
watch(online, (nextOnline, previousOnline) => {
if (previousOnline !== false || nextOnline !== true || otaVisible.value) return;
if (isCheckingOta) {
otaCheckQueuedForOnline = true;
return;
}
if (!versionInfo?.needUpdate) return;
applyOtaVersionInfo(versionInfo);
const dismissedAt = uni.getStorageSync("ota_dismissed_at");
const now = Date.now();
if (!otaInfo.value.forceUpdate && dismissedAt && now - dismissedAt < 24 * 60 * 60 * 1000) return;
otaState.value = "new_version";
otaVisible.value = true;
};
void checkOtaUpdate();
});
// 拼接 OTA WiFi 页参数,让未连 WiFi 的设备继续使用同一份版本信息。
const getOtaWifiUrl = () => {