【类 型】:fix 电量组件 未拿到飞机数据之前 渲染视图报错
【原 因】:没有数据之前渲染视图 【过 程】:给默认值 拿到数据在渲染视图 【影 响】: # 类型 包含: # feat:新功能(feature) # fix:修补bug # docs:文档(documentation) # style: 格式(不影响代码运行的变动) # refactor:重构(即不是新增功能,也不是修改bug的代码变动) # test:增加测试 # chore:构建过程或辅助工具的变动
This commit is contained in:
parent
032e5530c4
commit
0d2c74bfed
@ -1,10 +1,12 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="w-100" style="position: absolute;">
|
<div class="w-100 batteryBar">
|
||||||
<!-- <el-progress class="batteryBar" :percentage="plane.planeState.batteryRemaining" :show-text="false"
|
<el-progress class="z90" :percentage="batteryRemaining" :show-text="false" :stroke-width="3"></el-progress>
|
||||||
stroke-width="2"></el-progress> -->
|
<tooltip v-if="batteryRemainingPower" class="z90" :horizontalPosition="`${batteryRemaining}%`"
|
||||||
<el-progress class="batteryBar" :percentage="80" :show-text="false" stroke-width="4"></el-progress>
|
backgroundColor="#5cbb7a">
|
||||||
<tooltip class="rtlMark" :horizontalPosition="'20%'" backgroundColor="#ff3333">
|
{{ batteryRemainingPower }} mah
|
||||||
H
|
</tooltip>
|
||||||
|
<tooltip class="z90" :horizontalPosition="'20%'" backgroundColor="#ff3333">
|
||||||
|
返
|
||||||
</tooltip>
|
</tooltip>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -18,6 +20,37 @@ export default {
|
|||||||
return {
|
return {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
props: {
|
props: {
|
||||||
plane: {
|
plane: {
|
||||||
typeof: 'Object',
|
typeof: 'Object',
|
||||||
@ -26,6 +59,8 @@ export default {
|
|||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
Tooltip
|
Tooltip
|
||||||
|
},
|
||||||
|
created () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@ -34,10 +69,6 @@ export default {
|
|||||||
@import "@/styles/theme.scss";
|
@import "@/styles/theme.scss";
|
||||||
|
|
||||||
.batteryBar {
|
.batteryBar {
|
||||||
z-index: 90;
|
position: absolute;
|
||||||
}
|
|
||||||
|
|
||||||
.rtlMark {
|
|
||||||
z-index: 90;
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
<map-box ref="mapbox" :key="mapBoxKey" class="ofh">
|
<map-box ref="mapbox" :key="mapBoxKey" class="ofh">
|
||||||
<template #content>
|
<template #content>
|
||||||
<BatteryStatus :plane="plane" />
|
<BatteryStatus :plane="plane" />
|
||||||
<!-- <PlaneStatus :plane="plane" /> -->
|
|
||||||
<ControllerTabs :plane="plane" @mapXOffset="mapXOffset" @makeRoute="makeRoute" @clearRoute="clearRoute" />
|
<ControllerTabs :plane="plane" @mapXOffset="mapXOffset" @makeRoute="makeRoute" @clearRoute="clearRoute" />
|
||||||
</template>
|
</template>
|
||||||
</map-box>
|
</map-box>
|
||||||
@ -15,7 +14,6 @@ import mqtt from '@/utils/mqtt'
|
|||||||
import MapBox from '@/components/MapBox'
|
import MapBox from '@/components/MapBox'
|
||||||
import ControllerTabs from '@/components/ControllerTabs'
|
import ControllerTabs from '@/components/ControllerTabs'
|
||||||
import BatteryStatus from '@/components/BatteryStatus'
|
import BatteryStatus from '@/components/BatteryStatus'
|
||||||
// import PlaneStatus from '@/components/PlaneStatus'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Planes',
|
name: 'Planes',
|
||||||
@ -30,7 +28,6 @@ export default {
|
|||||||
MapBox,
|
MapBox,
|
||||||
ControllerTabs,
|
ControllerTabs,
|
||||||
BatteryStatus
|
BatteryStatus
|
||||||
// PlaneStatus
|
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
plane () {
|
plane () {
|
||||||
@ -105,8 +102,7 @@ export default {
|
|||||||
plane: {
|
plane: {
|
||||||
handler (val) {
|
handler (val) {
|
||||||
this.makePlane(val)// 有飞机数据之后 在地图上创建飞机
|
this.makePlane(val)// 有飞机数据之后 在地图上创建飞机
|
||||||
if (val.planeState.battCapacity === null) {
|
if (!val.planeState.battCapacity) {
|
||||||
console.log(val.planeState.battCapacity)
|
|
||||||
mqtt.publishFun(`cmd/${this.plane.macadd}`, '{"getBattCapacity":1}')// 发送设置飞机状态主题 请求飞控返回 电池总容量
|
mqtt.publishFun(`cmd/${this.plane.macadd}`, '{"getBattCapacity":1}')// 发送设置飞机状态主题 请求飞控返回 电池总容量
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user