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