jsy-app/components/custom-battery/custom-battery.vue
2024-11-27 18:46:21 +08:00

106 lines
1.7 KiB
Vue

<template>
<view class="battery-container">
<text v-if="showValue">{{ value }} </text>
<view v-if="online" :style="[`width:${value}%`]" :class="['battery-level', charging ? 'charging' : '']" />
<view v-else :style="[`width:${value}%`,'background-color: #aaa;']" class="battery-level" />
</view>
</template>
<script>
export default {
name: "Battery",
props: {
// 在线状态
online: {
type: Boolean,
default: false,
required: true
},
// 电量
value: {
type: [String, Number],
default: 0,
required: true
},
// 显示数值
showValue: {
type: Boolean,
default: true,
},
// 充电状态
charging: {
type: Boolean,
default: false,
},
// 颜色
fontColor: {
type: String,
default: "#333",
}
},
data() {
return {}
},
created() {},
methods: {}
}
</script>
<style lang="scss" scoped>
// 电池
.battery-container {
margin: 0 0 0 10px;
position: relative;
width: 31px;
height: 16px;
line-height: 14px;
background-color: #fff;
border-radius: 3px;
border: 1px solid #333;
text-align: center;
text {
position: relative;
z-index: 2;
}
}
.battery-container::after {
content: "";
position: absolute;
top: 4px;
right: -2px;
width: 1px;
height: 5px;
background-color: #333;
border-radius: 4px;
}
.battery-level {
height: 12px;
position: absolute;
top: 1px;
bottom: 0;
left: 1px;
width: 90%;
max-width: 95%;
background-color: #4CAF50;
border-radius: 2px;
transition: width 0.5s;
}
// 充电动画
@keyframes chargingWidth {
from {
width: 10%;
}
to {
width: 100%;
}
}
.charging {
animation: chargingWidth 2s infinite;
}
</style>