(fix)修复电池电量显示小数点故障
This commit is contained in:
parent
994d374615
commit
ae66a39b83
|
@ -19,6 +19,10 @@ class BatteryWidget extends GaiaWidget {
|
|||
|
||||
@state() percents = 100
|
||||
|
||||
getBatteryPercents() {
|
||||
return Number((this.batteryManager.level * 100).toPrecision(2))
|
||||
}
|
||||
|
||||
batteryManager!: BatteryManager
|
||||
|
||||
constructor({
|
||||
|
@ -51,8 +55,7 @@ class BatteryWidget extends GaiaWidget {
|
|||
|
||||
init = async () => {
|
||||
this.batteryManager = await navigator.getBattery()
|
||||
|
||||
this.percents = this.batteryManager.level * 100
|
||||
this.percents = this.getBatteryPercents()
|
||||
this.charge = this.batteryManager.charging
|
||||
this.lifeCycle = 'initialized'
|
||||
|
||||
|
@ -67,7 +70,7 @@ class BatteryWidget extends GaiaWidget {
|
|||
handleEvent(event: Event): void {
|
||||
switch (event.type) {
|
||||
case 'levelchange':
|
||||
this.percents = this.batteryManager.level * 100
|
||||
this.percents = this.getBatteryPercents()
|
||||
break
|
||||
case 'chargingchange':
|
||||
this.charge = this.batteryManager.charging
|
||||
|
|
Loading…
Reference in New Issue