update:优化性能问题

This commit is contained in:
2026-08-17 10:11:28 +08:00
parent 2628a17b3f
commit 63fb4ae85a
15 changed files with 395 additions and 137 deletions
+21 -5
View File
@@ -4,18 +4,34 @@ import { getDeviceBatteryAPI } from "@/apis";
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 () => {
const data = await getDeviceBatteryAPI();
power.value = data.battery;
timer.value = setInterval(async () => {
const data = await getDeviceBatteryAPI();
power.value = data.battery;
await refreshPower();
if (disposed) return;
timer.value = setInterval(() => {
void refreshPower();
}, 1000 * 10);
});
onBeforeUnmount(() => {
disposed = true;
clearInterval(timer.value);
timer.value = null;
});
</script>
+48 -28
View File
@@ -1,5 +1,5 @@
<script setup>
import { ref, watch, onMounted, onBeforeUnmount } from "vue";
import { ref, watch } from "vue";
const props = defineProps({
rowCount: {
type: Number,
@@ -29,42 +29,36 @@ const bgImages = [
"https://static.shelingxingqiu.com/shootmini/static/complete-light1.png",
"https://static.shelingxingqiu.com/shootmini/static/complete-light2.png",
];
const bgIndex = ref(0);
watch(
() => props.total,
(newValue) => {
items.value = new Array(newValue).fill(9);
}
);
const timer = ref(null);
onMounted(() => {
timer.value = setInterval(() => {
bgIndex.value = bgIndex.value === 0 ? 1 : 0;
}, 200);
});
onBeforeUnmount(() => {
if (timer.value) {
clearInterval(timer.value);
}
});
</script>
<template>
<view class="container">
<image
v-if="total > 0 && arrows.length === total && completeEffect"
:src="bgImages[bgIndex]"
class="complete-light"
:style="{
width: `calc(${(100 / (rowCount + 2)) * rowCount}vw + ${
(100 / (total * 2)) * (rowCount * 2 + (total === 12 ? 8 : 24))
}px)`,
height: `calc(${(100 / (rowCount + 2)) * (total / rowCount)}vw + ${
(100 / (total * 2)) *
((total / rowCount) * 2 + (total === 12 ? 7 : 24))
}px)`,
top: `${total === 12 ? -2 : -3}vw`,
}"
/>
<template v-if="total > 0 && arrows.length === total && completeEffect">
<image
v-for="(image, index) in bgImages"
:key="image"
:src="image"
:class="[
'complete-light',
index === 0 ? 'complete-light--first' : 'complete-light--second',
]"
:style="{
width: `calc(${(100 / (rowCount + 2)) * rowCount}vw + ${
(100 / (total * 2)) * (rowCount * 2 + (total === 12 ? 8 : 24))
}px)`,
height: `calc(${(100 / (rowCount + 2)) * (total / rowCount)}vw + ${
(100 / (total * 2)) *
((total / rowCount) * 2 + (total === 12 ? 7 : 24))
}px)`,
top: `${total === 12 ? -2 : -3}vw`,
}"
/>
</template>
<view
v-for="(_, index) in items"
:key="index"
@@ -121,4 +115,30 @@ onBeforeUnmount(() => {
.complete-light {
position: absolute;
}
.complete-light--first {
animation: complete-light-first 400ms steps(1, end) infinite;
}
.complete-light--second {
animation: complete-light-second 400ms steps(1, end) infinite;
}
@keyframes complete-light-first {
0%,
49.9% {
opacity: 1;
}
50%,
100% {
opacity: 0;
}
}
@keyframes complete-light-second {
0%,
49.9% {
opacity: 0;
}
50%,
100% {
opacity: 1;
}
}
</style>
+6 -1
View File
@@ -9,11 +9,13 @@ const props = defineProps({
const show = ref(false);
const count = ref(props.countdown);
const timer = ref(null);
const showTimer = ref(null);
const updateTimer = (value) => {
count.value = Math.round(value);
};
onMounted(() => {
setTimeout(() => {
showTimer.value = setTimeout(() => {
showTimer.value = null;
show.value = true;
timer.value = setInterval(() => {
if (count.value === 0) {
@@ -27,7 +29,10 @@ onMounted(() => {
uni.$on("update-timer", updateTimer);
});
onBeforeUnmount(() => {
if (showTimer.value) clearTimeout(showTimer.value);
showTimer.value = null;
if (timer.value) clearInterval(timer.value);
timer.value = null;
uni.$off("update-timer", updateTimer);
});
</script>
+23 -1
View File
@@ -1,6 +1,8 @@
<script setup>
import { computed } from "vue";
const MAX_VISIBLE_SCORE_CARDS = 60;
const props = defineProps({
arrows: {
type: Array,
@@ -32,8 +34,16 @@ const isFailed = (arrow = {}) => {
return arrow.ok !== true;
};
const hiddenScoreCount = computed(() =>
props.recordMode
? 0
: Math.max(props.arrows.length - MAX_VISIBLE_SCORE_CARDS, 0)
);
const displayArrows = computed(() => {
const list = [...props.arrows];
const list = props.recordMode
? [...props.arrows]
: props.arrows.slice(-MAX_VISIBLE_SCORE_CARDS);
// total 是达标箭数,不是实际射箭上限;训练中始终预留下一箭空框。
if (!props.recordMode) list.push(null);
return list;
@@ -42,6 +52,10 @@ const displayArrows = computed(() => {
<template>
<view v-if="displayArrows.length" class="score-panel">
<text v-if="hiddenScoreCount" class="score-window-tip">
已省略前 {{ hiddenScoreCount }} 仅显示最近
{{ MAX_VISIBLE_SCORE_CARDS }}
</text>
<view class="score-grid">
<view
v-for="(arrow, index) in displayArrows"
@@ -90,6 +104,14 @@ const displayArrows = computed(() => {
flex-wrap: wrap;
}
.score-window-tip {
display: block;
margin-bottom: 18rpx;
color: rgba(255, 255, 255, 0.6);
font-size: 22rpx;
line-height: 1.4;
}
.score-card {
position: relative;
width: 100rpx;