2024-07-23 21:11:36 +08:00
|
|
|
<template>
|
2024-07-24 16:45:05 +08:00
|
|
|
<div class="w-100 batteryBar">
|
|
|
|
<el-progress class="z90" :percentage="batteryRemaining" :show-text="false" :stroke-width="3"></el-progress>
|
|
|
|
<tooltip v-if="batteryRemainingPower" class="z90" :horizontalPosition="`${batteryRemaining}%`"
|
|
|
|
backgroundColor="#5cbb7a">
|
|
|
|
{{ batteryRemainingPower }} mah
|
|
|
|
</tooltip>
|
|
|
|
<tooltip class="z90" :horizontalPosition="'20%'" backgroundColor="#ff3333">
|
|
|
|
返
|
2024-07-23 21:11:36 +08:00
|
|
|
</tooltip>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import Tooltip from '@/components/Tag/Tooltip'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'BatteryStatus',
|
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
}
|
|
|
|
},
|
2024-07-24 16:45:05 +08:00
|
|
|
computed: {
|
|
|
|
// 电池剩余电量值 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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 如果上述检查未通过,返回 null
|
|
|
|
return null
|
|
|
|
},
|
|
|
|
// 剩余电量 百分比
|
|
|
|
batteryRemaining () {
|
|
|
|
if (this.plane && this.plane.planeState && this.plane.planeState.batteryRemaining !== undefined) {
|
|
|
|
const remaining = this.plane.planeState.batteryRemaining
|
|
|
|
if (remaining < 0) {
|
|
|
|
return 0
|
|
|
|
} else if (remaining > 100) {
|
|
|
|
return 100
|
|
|
|
} else {
|
|
|
|
return Number(remaining)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
2024-07-23 21:11:36 +08:00
|
|
|
props: {
|
|
|
|
plane: {
|
|
|
|
typeof: 'Object',
|
|
|
|
deep: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
Tooltip
|
2024-07-24 16:45:05 +08:00
|
|
|
},
|
|
|
|
created () {
|
2024-07-23 21:11:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
@import "@/styles/theme.scss";
|
|
|
|
|
|
|
|
.batteryBar {
|
2024-07-24 16:45:05 +08:00
|
|
|
position: absolute;
|
2024-07-23 21:11:36 +08:00
|
|
|
}
|
|
|
|
</style>
|