【类 型】:feat 电量条控件 变色功能

【原  因】:起警示作用
【过  程】:当前电量越接近返航所需电量 颜色越红
【影  响】:
This commit is contained in:
tk 2024-07-24 18:16:03 +08:00
parent 0d2c74bfed
commit 7490cff74d
2 changed files with 65 additions and 9 deletions

View File

@ -1,11 +1,12 @@
<template> <template>
<div class="w-100 batteryBar"> <div class="w-100 batteryBar">
<el-progress class="z90" :percentage="batteryRemaining" :show-text="false" :stroke-width="3"></el-progress> <el-progress class="z90" :percentage="batteryRemaining" :show-text="false" :stroke-width="3"
:color="statusColor"></el-progress>
<tooltip v-if="batteryRemainingPower" class="z90" :horizontalPosition="`${batteryRemaining}%`" <tooltip v-if="batteryRemainingPower" class="z90" :horizontalPosition="`${batteryRemaining}%`"
backgroundColor="#5cbb7a"> backgroundColor="#5cbb7a">
{{ batteryRemainingPower }} mah {{ batteryRemainingPower }} 毫安
</tooltip> </tooltip>
<tooltip class="z90" :horizontalPosition="'20%'" backgroundColor="#ff3333"> <tooltip v-if="rtlRemaining > 5" class="z90" :horizontalPosition="`${rtlRemaining}%`" backgroundColor="#ff3333">
</tooltip> </tooltip>
</div> </div>
@ -18,10 +19,30 @@ export default {
name: 'BatteryStatus', name: 'BatteryStatus',
data () { data () {
return { return {
rtlRemainingPower: 0
} }
}, },
computed: { computed: {
// mah statusColor () {
//
const remaining = this.batteryRemaining
const rtl = this.rtlRemaining
//
const percentage = remaining - rtl
// 0100
const normalizedPercentage = Math.max(0, Math.min(100, percentage))
// (0 - 360)
const startHue = 200 // #00C8C8
const endHue = 0 // #FF0000
//
const hue = Math.round(startHue + (endHue - startHue) * (100 - normalizedPercentage) / 100)
//
const saturation = 90 //
const lightness = 50 //
// HSL
return `hsl(${hue}, ${saturation}%, ${lightness}%)`
},
// ma
batteryRemainingPower () { batteryRemainingPower () {
// this.plane this.plane.planeState // this.plane this.plane.planeState
if (this.plane && this.plane.planeState) { if (this.plane && this.plane.planeState) {
@ -32,8 +53,8 @@ export default {
return (battCapacity / 100) * batteryRemaining return (battCapacity / 100) * batteryRemaining
} }
} }
// null // 0
return null return 0
}, },
// //
batteryRemaining () { batteryRemaining () {
@ -48,8 +69,18 @@ export default {
} }
} }
return 0 return 0
},
//
// rtlRemainingPower () {
// return 0
// },
//
rtlRemaining () {
if (this.plane && this.plane.planeState && this.plane.planeState.battCapacity) {
return this.rtlRemainingPower / this.plane.planeState.battCapacity * 100
}
return 0
} }
}, },
props: { props: {
plane: { plane: {
@ -61,6 +92,9 @@ export default {
Tooltip Tooltip
}, },
created () { created () {
setInterval(() => {
this.rtlRemainingPower += 10
}, 1)
} }
} }
</script> </script>

View File

@ -157,7 +157,6 @@ export default {
this.map.addControl(new mapboxgl.NavigationControl(), 'top-right')// this.map.addControl(new mapboxgl.NavigationControl(), 'top-right')//
// this.map.addControl(new mapboxgl.ScaleControl(), 'top-right')// // this.map.addControl(new mapboxgl.ScaleControl(), 'top-right')//
this.map.addControl(new mapboxgl.FullscreenControl(), 'top-right')// this.map.addControl(new mapboxgl.FullscreenControl(), 'top-right')//
// Add geolocate control to the map.
this.map.addControl( this.map.addControl(
new mapboxgl.GeolocateControl({ new mapboxgl.GeolocateControl({
positionOptions: { positionOptions: {
@ -168,7 +167,7 @@ export default {
// Draw an arrow next to the location dot to indicate which direction the device is heading. // Draw an arrow next to the location dot to indicate which direction the device is heading.
showUserHeading: true showUserHeading: true
}) })
) )//
}, },
/** /**
* @description: 清除地图上的航线 * @description: 清除地图上的航线
@ -517,6 +516,29 @@ export default {
} }
} }
} }
class CustomControl {
constructor({ label, onClick }) {
this._label = label
this._onClick = onClick
}
onAdd (map) {
this._map = map
this._container = document.createElement('div')
this._container.className = 'mapboxgl-ctrl mapboxgl-ctrl-group'
this._button = document.createElement('button')
this._button.textContent = this._label
this._button.onclick = this._onClick
this._container.appendChild(this._button)
return this._container
}
onRemove () {
this._container.parentNode.removeChild(this._container)
this._map = undefined
}
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>