feat: OTA 首页弹窗优化

This commit is contained in:
2026-08-18 10:30:16 +08:00
parent 6c55d32f90
commit 9e6ad4cf50
+34 -2
View File
@@ -1,5 +1,5 @@
<script setup> <script setup>
import {onMounted, onUnmounted, ref} from "vue"; import {onMounted, onUnmounted, ref, watch} from "vue";
import {onShareAppMessage, onShareTimeline, onShow} from "@dcloudio/uni-app"; import {onShareAppMessage, onShareTimeline, onShow} from "@dcloudio/uni-app";
import Container from "@/components/Container.vue"; import Container from "@/components/Container.vue";
import AppFooter from "@/components/AppFooter.vue"; import AppFooter from "@/components/AppFooter.vue";
@@ -52,6 +52,8 @@ const otaInfo = ref({
forceUpdate: false, forceUpdate: false,
}); });
const isStartingOta = ref(false); const isStartingOta = ref(false);
let isCheckingOta = false;
let otaCheckQueuedForOnline = false;
let otaProgressTimer = null; let otaProgressTimer = null;
let otaStatusTimer = null; let otaStatusTimer = null;
let otaTimeoutTimer = null; let otaTimeoutTimer = null;
@@ -91,13 +93,25 @@ const applyOtaVersionInfo = (versionInfo) => {
// 检查当前设备盒子是否存在可升级版本。 // 检查当前设备盒子是否存在可升级版本。
const checkOtaUpdate = async () => { const checkOtaUpdate = async () => {
if (isCheckingOta || otaVisible.value) return;
isCheckingOta = true;
try {
let deviceStatus;
try {
deviceStatus = await getDeviceBatteryAPI();
} catch (err) {
return;
}
if (deviceStatus?.online !== true || otaVisible.value) return;
let versionInfo; let versionInfo;
try { try {
versionInfo = await getHardwareBoxVersionAPI(); versionInfo = await getHardwareBoxVersionAPI();
} catch (err) { } catch (err) {
return; return;
} }
if (!versionInfo?.needUpdate) return; if (!versionInfo?.needUpdate || otaVisible.value) return;
applyOtaVersionInfo(versionInfo); applyOtaVersionInfo(versionInfo);
const dismissedAt = uni.getStorageSync("ota_dismissed_at"); const dismissedAt = uni.getStorageSync("ota_dismissed_at");
@@ -105,8 +119,26 @@ const checkOtaUpdate = async () => {
if (!otaInfo.value.forceUpdate && dismissedAt && now - dismissedAt < 24 * 60 * 60 * 1000) return; if (!otaInfo.value.forceUpdate && dismissedAt && now - dismissedAt < 24 * 60 * 60 * 1000) return;
otaState.value = "new_version"; otaState.value = "new_version";
otaVisible.value = true; 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;
}
void checkOtaUpdate();
});
// 拼接 OTA WiFi 页参数,让未连 WiFi 的设备继续使用同一份版本信息。 // 拼接 OTA WiFi 页参数,让未连 WiFi 的设备继续使用同一份版本信息。
const getOtaWifiUrl = () => { const getOtaWifiUrl = () => {
const { versionNumber, resourceUrl } = otaInfo.value; const { versionNumber, resourceUrl } = otaInfo.value;