feat: OTA 首页弹窗优化
This commit is contained in:
+34
-2
@@ -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,13 +93,25 @@ const applyOtaVersionInfo = (versionInfo) => {
|
||||
|
||||
// 检查当前设备盒子是否存在可升级版本。
|
||||
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;
|
||||
try {
|
||||
versionInfo = await getHardwareBoxVersionAPI();
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
if (!versionInfo?.needUpdate) return;
|
||||
if (!versionInfo?.needUpdate || otaVisible.value) return;
|
||||
applyOtaVersionInfo(versionInfo);
|
||||
|
||||
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;
|
||||
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;
|
||||
}
|
||||
void checkOtaUpdate();
|
||||
});
|
||||
|
||||
// 拼接 OTA WiFi 页参数,让未连 WiFi 的设备继续使用同一份版本信息。
|
||||
const getOtaWifiUrl = () => {
|
||||
const { versionNumber, resourceUrl } = otaInfo.value;
|
||||
|
||||
Reference in New Issue
Block a user