鸿宇研学生前端代码
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.

92 lines
1.8 KiB

1 day ago
  1. <template>
  2. <div class="progress">
  3. <div class="progress-item flex" v-for="(item, index) in arr" :key="`${code}-${index}`"
  4. :style="getStyle(item.index)"
  5. >
  6. {{ item.text }}
  7. </div>
  8. <div class="progress-text" :style="textStyle">
  9. <div class="flex" v-for="(item, index) in arr" :key="`${code}-text-${index}`" >
  10. {{ item.text }}
  11. </div>
  12. </div>
  13. </div>
  14. </template>
  15. <script>
  16. const WIDTH = 40;
  17. export default {
  18. props: {
  19. value: {
  20. default: 0
  21. }
  22. },
  23. data() {
  24. return {
  25. code: Math.floor(Math.random() * 100).toString()
  26. }
  27. },
  28. computed: {
  29. current() {
  30. return Math.floor(this.value / 20)
  31. },
  32. arr() {
  33. let arr = new Array(this.current).fill(1).map((item, index) => {
  34. return {
  35. text: `${(index + 1) * 20}%`,
  36. index,
  37. }
  38. })
  39. return arr.reverse()
  40. },
  41. textStyle() {
  42. const n = this.arr.length
  43. const width = WIDTH * n
  44. return `width: ${width}rpx; grid-template-columns: repeat(${n}, 1fr);`
  45. },
  46. },
  47. methods: {
  48. getStyle(index) {
  49. const width = WIDTH * (index + 1)
  50. return `width: ${width}rpx;`
  51. },
  52. },
  53. }
  54. </script>
  55. <style lang="scss" scoped>
  56. .progress {
  57. position: relative;
  58. font-size: 0;
  59. width: 100%;
  60. box-sizing: border-box;
  61. &-item {
  62. position: absolute;
  63. top: 0;
  64. left: 0;
  65. padding: 2rpx 0;
  66. font-size: 6rpx;
  67. color: transparent;
  68. background: #ee751c;
  69. border: 2rpx solid #FFFFFF;
  70. border-radius: 20rpx;
  71. &:first-child {
  72. }
  73. }
  74. &-text {
  75. position: absolute;
  76. display: grid;
  77. padding: 2rpx 0;
  78. font-size: 6rpx;
  79. color: #FFFFFF;
  80. background: transparent;
  81. border: 2rpx solid transparent;
  82. }
  83. }
  84. </style>