battery.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <view class="battery">
  3. <view v-if="isCharging" class="bgc charg" ></view>
  4. <view v-if="!isCharging" class="bgc" :style="{height: height,background:color}" ></view>
  5. <image :src="icon" class="img"></image>
  6. </view>
  7. </template>
  8. <script>
  9. export default {
  10. props: {
  11. battery:{
  12. type:Number,
  13. default:100
  14. }
  15. },
  16. data: () => ({
  17. // height:'30%',
  18. // color:'#85D1A9'
  19. }),
  20. computed: {
  21. isCharging(){
  22. return (this.battery > 100)
  23. },
  24. height(){
  25. if(this.battery > 100 || this.battery<0){
  26. return '0%'
  27. }
  28. return (this.battery*0.7)+'%'
  29. },
  30. color(){
  31. if(this.battery > 20){
  32. return '#85D1A9'
  33. }else{
  34. return '#C00000'
  35. }
  36. },
  37. icon(){
  38. if(this.battery > 100){
  39. return '../../static/common/battery_charg.svg'
  40. }else{
  41. return '../../static/common/battery.svg'
  42. }
  43. }
  44. },
  45. methods: {},
  46. watch: {},
  47. // 组件周期函数--监听组件挂载完毕
  48. mounted() {
  49. },
  50. // 组件周期函数--监听组件激活(显示)
  51. activated() {},
  52. // 组件周期函数--监听组件停用(隐藏)
  53. deactivated() {},
  54. // 组件周期函数--监听组件销毁之前
  55. beforeDestroy() {},
  56. };
  57. </script>
  58. <style>
  59. .battery{
  60. width: 13rpx;
  61. height: 45rpx;
  62. position: relative;
  63. display: flex;
  64. flex-direction: column;
  65. justify-content: flex-end;
  66. }
  67. .img{
  68. /* transform: translateY(-100%); */
  69. width: 13rpx;
  70. height: 45rpx;
  71. position:absolute;
  72. top: 0;
  73. }
  74. .bgc{
  75. width: 4rpx;
  76. /* height: 70%; */
  77. margin-left: auto;
  78. margin-right: auto;
  79. margin-bottom: 7rpx;
  80. background: #85D1A9;
  81. }
  82. .charg{
  83. animation: charging 1500ms linear infinite;
  84. }
  85. @keyframes charging
  86. {
  87. 0% {height: 0%;}
  88. 25% {height: 17%;}
  89. 50% {height: 35%;}
  90. 75% {height: 53%;}
  91. 100% {height: 70%;}
  92. }
  93. </style>