update:提交我的设备改版

This commit is contained in:
2026-09-17 18:23:41 +08:00
parent 46cbd37102
commit b060d8f987
50 changed files with 897 additions and 590 deletions
+5 -34
View File
@@ -1,44 +1,15 @@
<script setup>
import { ref, onMounted, onBeforeUnmount } from "vue";
import { getDeviceBatteryAPI } from "@/apis";
import useStore from "@/store";
import { storeToRefs } from "pinia";
const power = ref(0);
const timer = ref(null);
let disposed = false;
let requestInFlight = false;
const refreshPower = async () => {
if (disposed || requestInFlight) return;
requestInFlight = true;
try {
const data = await getDeviceBatteryAPI();
if (!disposed) power.value = data.battery;
} catch (_) {
// 电量轮询失败时等待下一轮,避免产生未处理的 Promise 拒绝。
} finally {
requestInFlight = false;
}
};
onMounted(async () => {
await refreshPower();
if (disposed) return;
timer.value = setInterval(() => {
void refreshPower();
}, 1000 * 10);
});
onBeforeUnmount(() => {
disposed = true;
clearInterval(timer.value);
timer.value = null;
});
const store = useStore();
const { deviceBattery: power } = storeToRefs(store);
</script>
<template>
<view class="container">
<image src="../static/b-power.png" mode="widthFix" />
<view>电量{{ power || 1 }}%</view>
<view>{{ power === null ? "电量--" : `电量${power}%` }}</view>
</view>
</template>
+11 -24
View File
@@ -1,10 +1,11 @@
<script setup>
import { computed } from "vue";
import { getDeviceBatteryAPI } from "@/apis";
import useStore from "@/store";
import { storeToRefs } from "pinia";
const OTA_MIN_BATTERY = 50;
const OTA_LOW_BATTERY_TEXT = "电量不足 50%,暂不支持 OTA 升级";
const OTA_OFFLINE_TEXT = "请先开启智能弓";
const store = useStore();
const { deviceStatus } = storeToRefs(store);
const props = defineProps({
visible: {
@@ -48,27 +49,13 @@ const isFailure = computed(() => props.state === "update_failure");
// Clamp progress to keep the progress bar width within its container.
const progressValue = computed(() => Math.min(100, Math.max(0, Number(props.progress) || 0)));
// 点击立即更新前先校验设备在线状态,再校验设备电量
const handleUpdateClick = async () => {
try {
const deviceStatus = await getDeviceBatteryAPI();
if (deviceStatus?.online !== true) {
uni.showToast({
title: OTA_OFFLINE_TEXT,
icon: "none",
});
return;
}
if (Number(deviceStatus?.battery) <= OTA_MIN_BATTERY) {
uni.showToast({
title: OTA_LOW_BATTERY_TEXT,
icon: "none",
});
return;
}
} catch (err) {
emit("update");
// 点击立即更新前先校验设备在线状态。
const handleUpdateClick = () => {
if (deviceStatus.value?.online !== true) {
uni.showToast({
title: OTA_OFFLINE_TEXT,
icon: "none",
});
return;
}
emit("update");
+1 -4
View File
@@ -12,12 +12,11 @@ import {
getHomeData,
getPhoneNumberAPI,
getPhoneNumberAPIv2,
getDeviceBatteryAPI,
} from "@/apis";
import useStore from "@/store";
const store = useStore();
const { updateUser, updateDevice, updateOnline, clearDevice } = store;
const { updateUser, updateDevice, clearDevice } = store;
const props = defineProps({
show: {
@@ -125,8 +124,6 @@ async function doLogin() {
devices.bindings[0].deviceId,
devices.bindings[0].deviceName
);
const data = await getDeviceBatteryAPI();
updateOnline(data.online);
} else {
clearDevice();
}