普兆健康管家前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
1.4 KiB

  1. <template>
  2. <view class="view"
  3. :style="style"
  4. >
  5. <view class="bar bg">
  6. <view
  7. v-for="(item, index) in list"
  8. :key="index"
  9. :class="['bar-item', index % 2 == 0 ? 'is-active' : '']"
  10. ></view>
  11. </view>
  12. <view class="bar fg">
  13. <view
  14. v-for="(item, index) in fgList"
  15. :key="index"
  16. :class="['bar-item', index % 2 == 0 ? 'is-active' : '']"
  17. ></view>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. export default {
  23. props: {
  24. progress: {
  25. type: Number,
  26. default: 0,
  27. },
  28. activeColor: {
  29. type: String,
  30. default: '#7451DE',
  31. },
  32. },
  33. data() {
  34. return {
  35. list: new Array(51).fill(1),
  36. }
  37. },
  38. computed: {
  39. fgList() {
  40. const num = Math.floor(51 * this.progress / 100)
  41. return this.list.slice(0, num + 1)
  42. },
  43. style() {
  44. return `--color: ${this.activeColor}`
  45. }
  46. },
  47. }
  48. </script>
  49. <style lang="scss" scoped>
  50. .view {
  51. position: relative;
  52. width: 100%;
  53. height: 28rpx;
  54. }
  55. .bar {
  56. width: 100%;
  57. height: 28rpx;
  58. display: grid;
  59. grid-template-columns: repeat(51, 1fr);
  60. &-item {
  61. }
  62. &.bg {
  63. .is-active {
  64. background: #989898;
  65. }
  66. }
  67. &.fg {
  68. position: absolute;
  69. top: 0;
  70. left: 0;
  71. .is-active {
  72. background: #7451DE;
  73. background: var(--color);
  74. }
  75. }
  76. }
  77. </style>