From 93d7dc044dc3eed3935f648a0681a61d499a3167 Mon Sep 17 00:00:00 2001 From: air <30444667+sszdot@users.noreply.github.com> Date: Wed, 25 Jun 2025 20:21:10 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E7=B1=BB=20=20=E5=9E=8B=E3=80=91?= =?UTF-8?q?=EF=BC=9Afix=20=E3=80=90=E5=8E=9F=20=20=E5=9B=A0=E3=80=91?= =?UTF-8?q?=EF=BC=9A1=20=20=E5=9C=B0=E5=9B=BE=E7=BB=84=E4=BB=B6=E7=BB=8F?= =?UTF-8?q?=E7=BA=AC=E5=BA=A6=E5=8F=8D=E4=BA=86=20=202.=E6=A6=82=E5=86=B5?= =?UTF-8?q?=E7=8A=B6=E6=80=81=20=E6=80=BB=E6=97=B6=E9=95=BFnow=E4=B8=8D?= =?UTF-8?q?=E8=83=BD=E5=AE=9E=E6=97=B6=E6=9B=B4=E6=96=B0=20=E6=9B=B4?= =?UTF-8?q?=E4=B8=BA=E7=94=A8setInterval=20=E3=80=90=E8=BF=87=20=20?= =?UTF-8?q?=E7=A8=8B=E3=80=91=EF=BC=9A=20=E3=80=90=E5=BD=B1=20=20=E5=93=8D?= =?UTF-8?q?=E3=80=91=EF=BC=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # 类型 包含: # feat:新功能(feature) # fix:修补bug # docs:文档(documentation) # style: 格式(不影响代码运行的变动) # refactor:重构(即不是新增功能,也不是修改bug的代码变动) # test:增加测试 # chore:构建过程或辅助工具的变动 --- src/components/MapBox.vue | 4 ++-- src/components/Statistics.vue | 24 +++++++++++------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/components/MapBox.vue b/src/components/MapBox.vue index 6e9b21f..31cd946 100644 --- a/src/components/MapBox.vue +++ b/src/components/MapBox.vue @@ -1043,8 +1043,8 @@ export default {
电压: ${stateObj.voltagBattery ?? '--'} V
电流: ${stateObj.currentBattery ?? '--'} A
高度: ${lastPos[2] ?? '--'} 米
-纬度: ${lastPos[0] ?? '--'}°
-经度: ${lastPos[1] ?? '--'}°
+经度: ${lastPos[0] ?? '--'}°
+纬度: ${lastPos[1] ?? '--'}°
对地速度: ${stateObj.groundSpeed ?? '--'} 米/秒
` diff --git a/src/components/Statistics.vue b/src/components/Statistics.vue index c031576..a804aba 100644 --- a/src/components/Statistics.vue +++ b/src/components/Statistics.vue @@ -44,6 +44,8 @@ export default { name: 'Statistics', data () { return { + now: Math.floor(Date.now() / 1000), // 当前秒级时间戳,用于实时更新 + timer: null } }, props: { @@ -52,8 +54,6 @@ export default { deep: true } }, - components: { - }, computed: { totalCount () { return Object.keys(this.planes || {}).length @@ -62,13 +62,12 @@ export default { return Object.values(this.planes || {}).filter(p => p.planeState?.online).length }, totalWorkingDuration () { - // 所有处于解锁状态的飞机,加上当前时长(当前时间 - startTime) - const now = Math.floor(Date.now() / 1000) + // 使用 this.now 保证每秒计算更新 return Object.values(this.planes || {}).reduce((total, p) => { const s = p.planeState?.flyDataSave?.startTime const isUnlock = p.planeState?.isUnlock if (isUnlock && s) { - return total + (now - s) + return total + (this.now - s) } return total }, 0) @@ -101,19 +100,18 @@ export default { const s = (sec % 60).toString().padStart(2, '0') return `${h}:${m}:${s}` } - }, - watch: { - - }, - methods: { - }, created () { + // 启动定时器,每秒刷新 now,从而触发 computed 更新 + this.timer = setInterval(() => { + this.now = Math.floor(Date.now() / 1000) + }, 1000) }, - destroyed () { + beforeDestroy () { + clearInterval(this.timer) } - } +