u-steps.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <view class="">
  3. <view class="u-steps" :style="{flexDirection: direction}">
  4. <view class="u-steps__item" :class="['u-steps__item--' + direction]" v-for="(item, index) in list"
  5. :key="index" @click="clickStep(index)">
  6. <view class="u-steps__item__num" v-if="mode == 'number'" :style="{
  7. backgroundColor: current < index ? 'transparent' : activeColor,
  8. borderColor: current < index ? unActiveColor : activeColor
  9. }">
  10. <text v-if="current < index" :style="{color: current < index ? unActiveColor : activeColor}">
  11. {{ index + 1 }}
  12. </text>
  13. <u-icon v-else size="22" color="#ffffff" :name="icon"></u-icon>
  14. </view>
  15. <view class="u-steps__item__dot" v-if="mode == 'dot'" :style="{
  16. backgroundColor: index <= current ? activeColor : unActiveColor
  17. }"></view>
  18. <text class="u-line-1" :style="{
  19. color: index <= current ? activeColor : unActiveColor,
  20. }" :class="['u-steps__item__text--' + direction]">
  21. {{ name ? item[name] : item.name}}
  22. </text>
  23. <view class="u-steps__item__line" :class="['u-steps__item__line--' + mode]"
  24. v-if="index < list.length - 1">
  25. <u-line :direction="direction" length="100%" :hair-line="false" :color="unActiveColor"></u-line>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. /**
  33. * steps 步骤条
  34. * @description 该组件一般用于完成一个任务要分几个步骤,标识目前处于第几步的场景。
  35. * @tutorial https://www.uviewui.com/components/steps.html
  36. * @property {String} mode 设置模式(默认dot)
  37. * @property {Array} list 数轴条数据,数组。具体见上方示例
  38. * @property {String} type type主题(默认primary)
  39. * @property {String} direction row-横向,column-竖向(默认row)
  40. * @property {Number String} current 设置当前处于第几步
  41. * @property {String} active-color 已完成步骤的激活颜色,如设置,type值会失效
  42. * @property {String} un-active-color 未激活的颜色,用于表示未完成步骤的颜色(默认#606266)
  43. * @example <u-steps :list="numList" active-color="#fa3534"></u-steps>
  44. */
  45. export default {
  46. name: 'u-steps',
  47. props: {
  48. // 自定义标题key
  49. name: {
  50. type: String,
  51. default: ''
  52. },
  53. // 步骤条的类型,dot|number
  54. mode: {
  55. type: String,
  56. default: 'dot'
  57. },
  58. // 步骤条的数据
  59. list: {
  60. type: Array,
  61. default () {
  62. return [];
  63. }
  64. },
  65. // 主题类型, primary|success|info|warning|error
  66. type: {
  67. type: String,
  68. default: 'primary'
  69. },
  70. // 当前哪一步是激活的
  71. current: {
  72. type: [Number, String],
  73. default: 0
  74. },
  75. // 激活步骤的颜色
  76. activeColor: {
  77. type: String,
  78. default: '#2979ff'
  79. },
  80. // 未激活的颜色
  81. unActiveColor: {
  82. type: String,
  83. default: '#909399'
  84. },
  85. // 自定义图标
  86. icon: {
  87. type: String,
  88. default: 'checkmark'
  89. },
  90. // step的排列方向,row-横向,column-竖向
  91. direction: {
  92. type: String,
  93. default: 'row'
  94. }
  95. },
  96. data() {
  97. return {};
  98. },
  99. methods: {
  100. clickStep(index) {
  101. this.$emit('change', index)
  102. }
  103. }
  104. };
  105. </script>
  106. <style lang="scss" scoped>
  107. @import '../../libs/css/style.components.scss';
  108. $u-steps-item-number-width: 44rpx;
  109. $u-steps-item-dot-width: 20rpx;
  110. .u-steps {
  111. @include vue-flex;
  112. .u-steps__item {
  113. flex: 1;
  114. text-align: center;
  115. position: relative;
  116. min-width: 100rpx;
  117. font-size: 26rpx;
  118. color: #8799a3;
  119. @include vue-flex;
  120. justify-content: center;
  121. flex-direction: column;
  122. align-items: center;
  123. &--row {
  124. @include vue-flex;
  125. flex-direction: column;
  126. .u-steps__item__line {
  127. position: absolute;
  128. z-index: 0;
  129. left: 75%;
  130. width: 50%;
  131. &--dot {
  132. top: calc(#{$u-steps-item-dot-width} / 2);
  133. }
  134. &--number {
  135. top: calc(#{$u-steps-item-number-width} / 2);
  136. }
  137. }
  138. }
  139. &--column {
  140. @include vue-flex;
  141. flex-direction: row;
  142. justify-content: flex-start;
  143. min-height: 120rpx;
  144. .u-steps__item__line {
  145. position: absolute;
  146. z-index: 0;
  147. height: 50%;
  148. top: 75%;
  149. &--dot {
  150. left: calc(#{$u-steps-item-dot-width} / 2);
  151. }
  152. &--number {
  153. left: calc(#{$u-steps-item-number-width} / 2);
  154. }
  155. }
  156. }
  157. &__num {
  158. @include vue-flex;
  159. align-items: center;
  160. justify-content: center;
  161. width: $u-steps-item-number-width;
  162. height: $u-steps-item-number-width;
  163. border: 1px solid #8799a3;
  164. border-radius: 50%;
  165. overflow: hidden;
  166. }
  167. &__dot {
  168. width: $u-steps-item-dot-width;
  169. height: $u-steps-item-dot-width;
  170. @include vue-flex;
  171. border-radius: 50%;
  172. }
  173. &__text--row {
  174. margin-top: 14rpx;
  175. }
  176. &__text--column {
  177. margin-left: 14rpx;
  178. }
  179. }
  180. }
  181. </style>