【类 型】:feat 电量显示组件 有大电流时 显示剩余续航

【原  因】:
【过  程】:
【影  响】:
This commit is contained in:
tk 2024-08-08 16:34:57 +08:00
parent 9a52ef4182
commit 9a8b55b42f

View File

@ -1,11 +1,19 @@
<template>
<div class="w-100 batteryBar">
<el-progress class="z90" :percentage="batteryRemaining" :show-text="false" :stroke-width="3"
:color="statusColor"></el-progress>
<tooltip v-if="batteryRemainingPower" class="z90" :horizontalPosition="`${batteryRemaining}%`"
:backgroundColor="statusColor">
{{ batteryRemainingPower }} mAh
<!-- 进度条显示剩余电量 -->
<el-progress class="z90" :percentage="batteryRemaining" :show-text="false" :stroke-width="3" :color="statusColor"></el-progress>
<!-- Tooltip 组件用于显示电量或续航时间 -->
<tooltip v-if="showTooltip" class="z90" :horizontalPosition="`${batteryRemaining}%`" :backgroundColor="statusColor">
<template v-if="showBattery">
{{ batteryRemainingPower }} mAh
</template>
<template v-else>
{{ endurance }} 分钟
</template>
</tooltip>
<!-- 当返航剩余电量大于 5 显示返航提示 -->
<tooltip v-if="rtlRemaining > 5" class="z90" :horizontalPosition="`${rtlRemaining}%`" backgroundColor="#ff3333">
</tooltip>
@ -19,7 +27,9 @@ export default {
name: 'BatteryStatus',
data () {
return {
rtlRemainingPower: 0
rtlRemainingPower: 0, //
showBattery: true, //
interval: null // ID
}
},
computed: {
@ -29,7 +39,7 @@ export default {
const rtl = this.rtlRemaining
//
const percentage = remaining - rtl
// 0100
// 0 100
const normalizedPercentage = Math.max(0, Math.min(100, percentage))
// (0 - 360)
const startHue = 200 // #00C8C8
@ -39,24 +49,32 @@ export default {
//
const saturation = 90 //
const lightness = 50 //
// HSL
// HSL
return `hsl(${hue}, ${saturation}%, ${lightness}%)`
},
// ma
// (mAh)
batteryRemainingPower () {
// this.plane this.plane.planeState
if (this.plane && this.plane.planeState) {
const battCapacity = this.plane.planeState.battCapacity
const batteryRemaining = this.plane.planeState.batteryRemaining
// battCapacity batteryRemaining
if (battCapacity !== undefined && batteryRemaining !== undefined) {
return (battCapacity / 100) * batteryRemaining
}
}
// 0
return 0
},
//
// ()
endurance () {
if (this.plane && this.plane.planeState && this.plane.planeState.currentBattery > 2) {
return Math.floor(this.batteryRemainingPower / 1000 / this.plane.planeState.currentBattery * 60)
}
return 0
},
// Tooltip
showTooltip () {
return this.batteryRemainingPower || this.endurance
},
// ()
batteryRemaining () {
if (this.plane && this.plane.planeState && this.plane.planeState.batteryRemaining !== undefined) {
const remaining = this.plane.planeState.batteryRemaining
@ -70,11 +88,7 @@ export default {
}
return 0
},
//
// rtlRemainingPower () {
// return 0
// },
//
// ()
rtlRemaining () {
if (this.plane && this.plane.planeState && this.plane.planeState.battCapacity) {
return this.rtlRemainingPower / this.plane.planeState.battCapacity * 100
@ -84,17 +98,54 @@ export default {
},
props: {
plane: {
typeof: 'Object',
type: Object,
deep: true
}
},
components: {
Tooltip
},
created () {
setInterval(() => {
this.rtlRemainingPower += 0
}, 1)
methods: {
/**
* 剩余电量与剩余续航时间轮播
*/
startInterval () {
this.interval = setInterval(() => {
this.showBattery = !this.showBattery
}, 3000)
},
clearInterval () {
if (this.interval) {
clearInterval(this.interval)
this.interval = null
}
},
checkDisplayConditions () {
this.clearInterval()
//
if (this.batteryRemainingPower > 0 && this.endurance > 0) {
this.startInterval()
}
}
},
watch: {
batteryRemainingPower () {
this.checkDisplayConditions()
},
endurance (val) {
this.checkDisplayConditions()
if (val === 0) {
this.showBattery = true
}
}
},
mounted () {
//
this.checkDisplayConditions()
},
beforeDestroy () {
//
this.clearInterval()
}
}
</script>