u-steps.vue 4.5 KB

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