progressBox.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <el-card>
  3. <div class="progress-container">
  4. <ul>
  5. <li
  6. v-for="(item, index) in stepList"
  7. :key="index"
  8. :class="{ active: active >= index }"
  9. >
  10. <el-tooltip class="item" effect="dark" :content="item.taskTypeName" placement="top">
  11. <p>{{ item.taskTypeName }}</p>
  12. </el-tooltip>
  13. <div
  14. class="progress-box"
  15. :style="`backgroundImage:linear-gradient(to top, var(--color-primary), var(--color-primary) ${item.percent},#fff ${item.percent}, #fff);`"
  16. ></div>
  17. <p class="num">{{ item.number }}</p>
  18. </li>
  19. </ul>
  20. </div>
  21. </el-card>
  22. </template>
  23. <script>
  24. export default {
  25. props: {
  26. // active: {
  27. // type: [Number, String],
  28. // default: 3
  29. // },
  30. list:{
  31. type: Array,
  32. default: []
  33. },
  34. total:{
  35. type:Number,
  36. default:1
  37. }
  38. },
  39. data () {
  40. return {
  41. stepList: [],
  42. active:-1
  43. };
  44. },
  45. watch: {
  46. list: {
  47. handler () {
  48. if (this.list.length) {
  49. this.stepList = this.list
  50. this.stepList.map((item,index)=>{
  51. item.percent = ( item.number / this.total)*100 + '%'
  52. })
  53. const active = this.stepList.findIndex((item) => item.number === 0)
  54. if(active==-1){
  55. this.active = this.stepList.length-1
  56. }
  57. }
  58. },
  59. immediate: true
  60. }
  61. },
  62. methods:{
  63. }
  64. };
  65. </script>
  66. <style lang="scss" scoped>
  67. .progress-container {
  68. width: 100%;
  69. overflow-x: auto;
  70. ul {
  71. list-style: none;
  72. display: flex;
  73. justify-content: flex-start;
  74. align-items: center;
  75. li {
  76. display: flex;
  77. flex-wrap: wrap;
  78. justify-content: center;
  79. flex: 1;
  80. position: relative;
  81. min-width: 110px;
  82. &::after {
  83. content: '';
  84. position: absolute;
  85. left: 0;
  86. right: 0;
  87. top: 50%;
  88. transform: translateY(-50%);
  89. height: 1px;
  90. background-color: #ccc;
  91. }
  92. &:first-of-type::after {
  93. left: 50%;
  94. }
  95. &:last-of-type::after {
  96. right: 50%;
  97. }
  98. &.active {
  99. &::after {
  100. background-color: var(--color-primary);
  101. }
  102. .progress-box {
  103. border-color: var(--color-primary);
  104. }
  105. }
  106. .el-tooltip{
  107. width: 100%;
  108. text-align: center;
  109. white-space: nowrap; /* 不换行 */
  110. overflow: hidden; /* 超出部分隐藏 */
  111. text-overflow: ellipsis; /* 显示省略号 */
  112. }
  113. .num,
  114. .text {
  115. width: 100%;
  116. text-align: center;
  117. }
  118. .progress-box {
  119. position: relative;
  120. z-index: 1;
  121. width: 32px;
  122. height: 32px;
  123. margin: 10px 0;
  124. border-radius: 50%;
  125. // background-color: #fff;
  126. border: 1px solid #ccc;
  127. }
  128. }
  129. }
  130. }
  131. </style>