u-steps.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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="name">
  20. ce
  21. </view>
  22. <view class="u-steps__item__dot" v-if="mode == 'dot'" :style="{
  23. backgroundColor: index <= current ? activeColor : unActiveColor
  24. }"></view>
  25. <text class="u-line-1" :style="{
  26. color: index <= current ? activeColor : unActiveColor,
  27. }" :class="['u-steps__item__text--' + direction]">
  28. {{ item.created_at }}
  29. </text>
  30. <view class="u-steps__item__line" :class="['u-steps__item__line--' + mode]"
  31. v-if="index < list.length - 1">
  32. <u-line :direction="direction" length="100%" :hair-line="false" :color="unActiveColor"></u-line>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. /**
  40. * steps 步骤条
  41. * @description 该组件一般用于完成一个任务要分几个步骤,标识目前处于第几步的场景。
  42. * @tutorial https://www.uviewui.com/components/steps.html
  43. * @property {String} mode 设置模式(默认dot)
  44. * @property {Array} list 数轴条数据,数组。具体见上方示例
  45. * @property {String} type type主题(默认primary)
  46. * @property {String} direction row-横向,column-竖向(默认row)
  47. * @property {Number String} current 设置当前处于第几步
  48. * @property {String} active-color 已完成步骤的激活颜色,如设置,type值会失效
  49. * @property {String} un-active-color 未激活的颜色,用于表示未完成步骤的颜色(默认#606266)
  50. * @example <u-steps :list="numList" active-color="#fa3534"></u-steps>
  51. */
  52. export default {
  53. name: 'u-steps',
  54. props: {
  55. // 步骤条的类型,dot|number
  56. mode: {
  57. type: String,
  58. default: 'dot'
  59. },
  60. // 步骤条的数据
  61. list: {
  62. type: Array,
  63. default () {
  64. return [];
  65. }
  66. },
  67. // 主题类型, primary|success|info|warning|error
  68. type: {
  69. type: String,
  70. default: 'primary'
  71. },
  72. // 当前哪一步是激活的
  73. current: {
  74. type: [Number, String],
  75. default: 0
  76. },
  77. // 激活步骤的颜色
  78. activeColor: {
  79. type: String,
  80. default: '#10C08C'
  81. },
  82. // 未激活的颜色
  83. unActiveColor: {
  84. type: String,
  85. default: '#10C08C'
  86. },
  87. // 自定义图标
  88. icon: {
  89. type: String,
  90. default: 'checkmark'
  91. },
  92. // step的排列方向,row-横向,column-竖向
  93. direction: {
  94. type: String,
  95. default: 'row'
  96. }
  97. },
  98. data() {
  99. return {};
  100. },
  101. };
  102. </script>
  103. <style lang="scss" scoped>
  104. @import '../../libs/css/style.components.scss';
  105. $u-steps-item-number-width: 44rpx;
  106. $u-steps-item-dot-width: 20rpx;
  107. .name {
  108. display: block;
  109. }
  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>