u-steps.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <view class="">
  3. <view class="u-steps">
  4. <view class="u-steps-item" v-for="(item,index) in list" :key="index">
  5. <view class="u-steps-item-num" v-if="mode == 'number' && current < index">{{index+1}}</view>
  6. <view class="u-steps-item-dot" v-if="mode == 'dot'" :style="{backgroundColor: index <= current ? innerActiveColor : unActiveColor}"></view>
  7. <u-icon size="22" class="u-steps-item-checked" :style="{backgroundColor: index <= current ? innerActiveColor : unActiveColor}"
  8. v-if="mode == 'number' && current >= index" name="checkmark"></u-icon>
  9. <text :style="{color: index <= current ? innerActiveColor : unActiveColor}">{{item.name}}</text>
  10. <view class="u-steps-item-line" :style="{backgroundColor: index <= current ? innerActiveColor : unActiveColor, top: mode == 'dot' ? '24rpx' : '36rpx'}">
  11. </view>
  12. </view>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. /**
  18. * steps 步骤条
  19. * @description 该组件一般用于完成一个任务要分几个步骤,标识目前处于第几步的场景。
  20. * @tutorial https://www.uviewui.com/components/steps.html
  21. * @property {String} mode 设置模式(默认dot)
  22. * @property {Array} list 数轴条数据,数组。具体见上方示例
  23. * @property {String} type type主题(默认primary)
  24. * @property {Number String} current 设置当前处于第几步
  25. * @property {String} active-color 已完成步骤的激活颜色,如设置,type值会失效
  26. * @property {String} un-active-color 未激活的颜色,用于表示未完成步骤的颜色(默认#606266)
  27. * @example <u-steps :list="numList" active-color="#fa3534"></u-steps>
  28. */
  29. export default {
  30. name: "u-steps",
  31. props: {
  32. // 步骤条的类型,dot|number
  33. mode: {
  34. type: String,
  35. default: 'dot'
  36. },
  37. // 步骤条的数据
  38. list: {
  39. type: Array,
  40. default () {
  41. return []
  42. }
  43. },
  44. // 主题类型, primary|success|info|warning|error
  45. type: {
  46. type: String,
  47. default: 'primary'
  48. },
  49. // 当前哪一步是激活的
  50. current: {
  51. type: [Number, String],
  52. default: 0
  53. },
  54. // 激活步骤的颜色
  55. activeColor: {
  56. type: String,
  57. default: ''
  58. },
  59. // 未激活的颜色
  60. unActiveColor: {
  61. type: String,
  62. default: '#606266'
  63. }
  64. },
  65. data() {
  66. return {
  67. }
  68. },
  69. computed: {
  70. innerActiveColor() {
  71. if (this.activeColor) return this.activeColor;
  72. else if (this.type) return this.$u.color[this.type];
  73. else return "#2979ff";
  74. },
  75. }
  76. }
  77. </script>
  78. <style lang="scss" scoped>
  79. .u-steps {
  80. display: flex;
  81. }
  82. .u-steps-item {
  83. flex: 1;
  84. text-align: center;
  85. position: relative;
  86. min-width: 100rpx;
  87. font-size: 26rpx;
  88. color: #8799a3;
  89. }
  90. .u-steps-item .u-steps-item-line {
  91. content: "";
  92. position: absolute;
  93. height: 2rpx;
  94. width: calc(100% - 80rpx);
  95. left: calc(0rpx - (100% - 80rpx) / 2);
  96. top: 36rpx;
  97. z-index: 0;
  98. }
  99. .u-steps-item:first-child .u-steps-item-line {
  100. display: none;
  101. }
  102. .u-steps-item-num {
  103. display: flex;
  104. align-items: center;
  105. justify-content: center;
  106. width: 44rpx;
  107. height: 44rpx;
  108. border: 1px solid #8799a3;
  109. border-radius: 50%;
  110. margin: 14rpx auto;
  111. overflow: hidden;
  112. }
  113. .u-steps-item-dot {
  114. width: 20rpx;
  115. height: 20rpx;
  116. display: flex;
  117. border-radius: 50%;
  118. margin: 14rpx auto;
  119. }
  120. .u-steps-item-checked {
  121. display: flex;
  122. align-items: center;
  123. justify-content: center;
  124. width: 44rpx;
  125. color: #fff !important;
  126. height: 44rpx;
  127. border-radius: 50%;
  128. margin: 14rpx auto;
  129. overflow: hidden;
  130. }
  131. </style>