2025-05-16 15:56:54 +08:00
|
|
|
<script setup>
|
2025-10-29 17:26:27 +08:00
|
|
|
import { ref, onMounted, onBeforeUnmount } from "vue";
|
|
|
|
|
import { getDeviceBatteryAPI } from "@/apis";
|
|
|
|
|
|
|
|
|
|
const power = ref(0);
|
|
|
|
|
const timer = ref(null);
|
|
|
|
|
|
|
|
|
|
onMounted(async () => {
|
2025-10-29 18:07:42 +08:00
|
|
|
const data = await getDeviceBatteryAPI();
|
|
|
|
|
power.value = data.battery;
|
2025-10-29 17:26:27 +08:00
|
|
|
timer.value = setInterval(async () => {
|
|
|
|
|
const data = await getDeviceBatteryAPI();
|
|
|
|
|
power.value = data.battery;
|
|
|
|
|
}, 1000 * 10);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
onBeforeUnmount(() => {
|
|
|
|
|
clearInterval(timer.value);
|
2025-05-16 15:56:54 +08:00
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
2025-06-15 20:55:34 +08:00
|
|
|
<view class="container" :style="{ opacity: power > 0 ? 1 : 0 }">
|
2025-05-16 15:56:54 +08:00
|
|
|
<image src="../static/b-power.png" mode="widthFix" />
|
|
|
|
|
<view>电量{{ power }}%</view>
|
|
|
|
|
</view>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
.container {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
2025-08-13 16:44:25 +08:00
|
|
|
color: #ffffffa8;
|
2025-05-16 15:56:54 +08:00
|
|
|
font-size: 13px;
|
|
|
|
|
}
|
|
|
|
|
.container > image {
|
2025-08-13 16:44:25 +08:00
|
|
|
width: 20px;
|
2025-05-16 15:56:54 +08:00
|
|
|
margin-right: 5px;
|
|
|
|
|
}
|
|
|
|
|
</style>
|