【类 型】:feat 返航子组件

【原  因】:
【过  程】:获取home点坐标 和 飞机坐标算出返航距离 算出返航时间 和 所需电量  组件百分之显示到电量进度条上
【影  响】:
This commit is contained in:
tk 2024-08-15 15:37:46 +08:00
parent 99cc2c193a
commit e78c432de2
4 changed files with 55 additions and 112 deletions

View File

@ -1,7 +1,8 @@
<template>
<div class="w-100 batteryBar">
<!-- 进度条显示剩余电量 -->
<el-progress class="z90" :percentage="batteryRemaining" :show-text="false" :stroke-width="3" :color="statusColor"></el-progress>
<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">
@ -14,7 +15,7 @@
</tooltip>
<!-- 当返航剩余电量大于 5 显示返航提示 -->
<tooltip v-if="rtlRemaining > 5" class="z90" :horizontalPosition="`${rtlRemaining}%`" backgroundColor="#ff3333">
<tooltip v-if="rtlRemaining > 0" class="z90" :horizontalPosition="`${rtlRemaining}%`" backgroundColor="#ff3333">
</tooltip>
</div>
@ -22,12 +23,12 @@
<script>
import Tooltip from '@/components/Tooltip'
import geodist from 'geodist'
export default {
name: 'BatteryStatus',
data () {
return {
rtlRemainingPower: 0, //
showBattery: true, //
interval: null // ID
}
@ -90,10 +91,48 @@ export default {
},
// ()
rtlRemaining () {
if (this.plane && this.plane.planeState && this.plane.planeState.battCapacity) {
return this.rtlRemainingPower / this.plane.planeState.battCapacity * 100
let rtlTime = 0 //
if (this.planePosition && this.homePosition && this.wpnavSpeed) {
const planeLngLat = { lat: this.planePosition[1], lon: this.planePosition[0] }
const homeLngLat = { lat: this.homePosition.lat, lon: this.homePosition.lng }
const horizontalDistance = geodist(planeLngLat, homeLngLat, { unit: 'meters' }) //
const verticalDistance = Math.abs(this.planePosition[2] - this.homePosition.alt) //
const rtlDistance = horizontalDistance + verticalDistance // +
rtlTime = Math.floor(Number(rtlDistance) / Number(this.wpnavSpeed)) //
}
return 0
if (rtlTime <= 0) {
return 0
}
const currentBattery = this.plane.planeState.currentBattery // ()
const batteryCapacity = this.plane.planeState.battCapacity // (mAh)
// mAh线
const rtlPowerRequired = rtlTime * currentBattery / 3.6 // (mAh)
console.log(rtlPowerRequired)
//
const rtlPowerPercentage = (rtlPowerRequired / batteryCapacity) * 100
// 0 100
return Math.max(0, Math.min(100, rtlPowerPercentage))
},
//
homePosition () {
if (this.plane && this.plane.planeState) {
return this.plane.planeState.homePosition
}
return null
},
//
planePosition () {
if (this.plane && this.plane.planeState) {
return this.plane.planeState.position[0]
}
return null
},
//
wpnavSpeed () {
if (this.plane && this.plane.planeState) {
return this.plane.planeState.wpnavSpeed
}
return null
}
},
props: {

View File

@ -1,103 +0,0 @@
<template>
<div>
<el-row class="m-15" type="flex" justify="space-between">
<el-col :span="2">
<PublicTag icon="icon-weixing" :val="plane.planeState.satCount" unit="颗" state="normal" />
</el-col>
<el-col :span="2">
<PublicTag icon="icon-weixing" :val="plane.planeState.voltagBattery" unit="V" state="normal" />
</el-col>
<el-col :span="2">
<PublicTag icon="icon-weixing" :val="plane.planeState.loadweight" unit="克" state="normal" />
</el-col>
<el-col :span="2">
<PublicTag icon="icon-gaodu" :val="plane.planeState.state" unit="状" state="normal" />
</el-col>
<el-col :span="3">
<HeartTag :heartBeat="plane.planeState.heartBeat" :heartRandom="plane.planeState.heartRandom"
:getPlaneMode="plane.planeState.getPlaneMode" />
</el-col>
<el-col :span="2">
<PublicTag icon="icon-mianxingdiaogou" :val="plane.planeState.hookstatus" unit="" state="normal" />
</el-col>
<el-col :span="2">
<PublicTag icon="icon-gaodu" :val="plane.planeState.positionAlt" unit="米" state="normal" />
</el-col>
<el-col :span="2">
<PublicTag icon="icon-gaodu" :val="plane.planeState.currentBattery" unit="安" state="danger" />
</el-col>
<el-col :span="2">
<PublicTag icon="icon-gaodu" :val="plane.planeState.battCapacity" unit="%" state="danger" />
</el-col>
</el-row>
<div class="batteryBox">
<!-- <el-progress :percentage="plane.planeState.batteryRemaining" :show-text="false" stroke-width="2"></el-progress>
<tooltip :horizontalPosition="'80%'" backgroundColor="#ff3333">
H
</tooltip> -->
</div>
</div>
</template>
<script>
import HeartTag from '@/components/Tag/HeartTag'
import PublicTag from '@/components/Tag/PublicTag'
// import Tooltip from '@/components/Tag/Tooltip'
import geodist from 'geodist'
export default {
name: 'PlaneStatus',
data () {
return {
distance: 0
}
},
props: {
plane: {
typeof: 'Object',
deep: true
}
},
components: {
HeartTag,
PublicTag
// Tooltip
},
computed: {
},
watch: {
distance (val) {
console.log(val + '米')
}
},
methods: {},
created () {
try {
const point1 = { lat: 52.518611, lon: 13.408056 }
const point2 = { lat: 51.507222, lon: -0.1275 }
this.distance = geodist(point1, point2, { unit: 'meters' })
} catch (error) {
console.error('Error calculating distance:', error)
}
}
}
</script>
<style lang="scss" scoped>
@import "@/styles/theme.scss";
.el-row {
z-index: 90;
}
.batteryBox {}
.batteryBox .el-progress {
z-index: 90;
}
.batteryBox .el-tooltip {
z-index: 90;
}
</style>

View File

@ -274,7 +274,7 @@ const store = new Vuex.Store({
voltagBattery: null, // 电压信息
currentBattery: null, // 电流信息
batteryRemaining: null, // 电池电量
positionAlt: null, // 高度信息
positionAlt: null, // 海拔高度信息
groundSpeed: null, // 对地速度
satCount: null, // 卫星数量
latitude: null, // 纬度
@ -285,9 +285,10 @@ const store = new Vuex.Store({
getPlaneMode: null, // 飞机模式
loadweight: null, // 重量
hookstatus: null, // 钩子状态
position: [], // [[经度,维度,海拔高度]]累计数组
position: [], // [[经度,维度,相对高度]]累计数组
battCapacity: null, // 电池容量
homePosition: null // 返航点位置
homePosition: null, // 返航点位置
wpnavSpeed: null// 飞机返航速度 米/秒
}
})
if (res.data.status === 1) {

View File

@ -103,6 +103,12 @@ export default {
if (plane.planeState.position.length > 1000) {
plane.planeState.position.shift() //
}
} else if (key === 'homePosition') {
const homePosition = JSON.parse(jsonData.homePosition)// home
homePosition.lng = homePosition.lng / 10e6
homePosition.lat = homePosition.lat / 10e6
homePosition.alt = Number(homePosition.alt)
plane.planeState[key] = homePosition
} else if (key === 'statusText') {
/* 飞控信息 插入日志 */
this.$store.dispatch('fetchLog', { content: jsonData[key], color: '#f57c00' })