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) } - } +