battery.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <div
  3. class="electric"
  4. :class="bgClass"
  5. >
  6. <div class="electric-panel">
  7. <div
  8. class="electric-panel-remainder"
  9. :style="{ width: quantity + '%' }"
  10. />
  11. </div>
  12. <div class="electric-berText">
  13. {{ quantity }}%
  14. </div>
  15. </div>
  16. </template>
  17. <script setup lang="ts">
  18. import { computed } from 'vue'
  19. const props = defineProps<{
  20. quantity: number
  21. }>()
  22. const bgClass = computed(() => {
  23. if (props.quantity >= 50) {
  24. return 'success'
  25. } if (props.quantity >= 20) {
  26. return 'warning'
  27. } if (props.quantity >= 1) {
  28. return 'danger'
  29. }
  30. return 'danger'
  31. })
  32. </script>
  33. <style scoped lang="scss">
  34. .electric {
  35. display: flex;
  36. justify-content: center;
  37. align-items: center;
  38. position: relative;
  39. color: white;
  40. &-panel {
  41. box-sizing: border-box;
  42. width: 25px;
  43. height: 15px;
  44. position: relative;
  45. border: 2px solid #ccc;
  46. padding: 1px;
  47. border-radius: 3px;
  48. margin-right: 5px;
  49. &::before {
  50. content: "";
  51. border-radius: 0 1px 1px 0;
  52. height: 8px;
  53. background: #ccc;
  54. width: 3px;
  55. position: absolute;
  56. top: 50%;
  57. right: -4px;
  58. transform: translateY(-50%);
  59. overflow: hidden;
  60. }
  61. &-remainder {
  62. border-radius: 1px;
  63. position: relative;
  64. height: 100%;
  65. width: 0%;
  66. left: 0;
  67. top: 0;
  68. background: #fff;
  69. }
  70. }
  71. &-berText {
  72. font-size: 15px;
  73. }
  74. }
  75. .success {
  76. color: #40d7c1;
  77. &>div:first-child::before,
  78. &>div:first-child>div {
  79. background-color: #40d7c1;
  80. }
  81. &>div:first-child {
  82. border-color: #40d7c1;
  83. }
  84. }
  85. .warning {
  86. color: #f90;
  87. &>div:first-child::before,
  88. &>div:first-child>div {
  89. background-color: #f90;
  90. }
  91. &>div:first-child {
  92. border-color: #f90;
  93. }
  94. }
  95. .danger {
  96. color: #ed4014;
  97. &>div:first-child::before,
  98. &>div:first-child>div {
  99. background-color: #ed4014;
  100. }
  101. &>div:first-child {
  102. border-color: #ed4014;
  103. }
  104. }
  105. </style>