u-steps.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. <text class="dis f-c a-start pathTraceColor" v-for="(value, key, index) in item"
  26. :class="{' active':key=='time'}" :key="index">{{ value }}</text>
  27. </text>
  28. <view class="u-steps__item__line" :class="['u-steps__item__line--' + mode]"
  29. v-if="index < list.length - 1">
  30. <u-line :direction="direction" length="100%" :hair-line="false" :color="unActiveColor"
  31. margin="10px 0"></u-line>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. /**
  39. * steps 步骤条
  40. * @description 该组件一般用于完成一个任务要分几个步骤,标识目前处于第几步的场景。
  41. * @tutorial https://www.uviewui.com/components/steps.html
  42. * @property {String} mode 设置模式(默认dot)
  43. * @property {Array} list 数轴条数据,数组。具体见上方示例
  44. * @property {String} type type主题(默认primary)
  45. * @property {String} direction row-横向,column-竖向(默认row)
  46. * @property {Number String} current 设置当前处于第几步
  47. * @property {String} active-color 已完成步骤的激活颜色,如设置,type值会失效
  48. * @property {String} un-active-color 未激活的颜色,用于表示未完成步骤的颜色(默认#606266)
  49. * @example <u-steps :list="numList" active-color="#fa3534"></u-steps>
  50. */
  51. export default {
  52. name: 'u-steps',
  53. props: {
  54. // 步骤条的类型,dot|number
  55. mode: {
  56. type: String,
  57. default: 'dot'
  58. },
  59. // 步骤条的数据
  60. list: {
  61. type: Array,
  62. default () {
  63. return [];
  64. }
  65. },
  66. // 主题类型, primary|success|info|warning|error
  67. type: {
  68. type: String,
  69. default: 'primary'
  70. },
  71. // 当前哪一步是激活的
  72. current: {
  73. type: [Number, String],
  74. default: 0
  75. },
  76. // 激活步骤的颜色
  77. activeColor: {
  78. type: String,
  79. default: '#2979ff'
  80. },
  81. // 未激活的颜色
  82. unActiveColor: {
  83. type: String,
  84. default: '#909399'
  85. },
  86. // 自定义图标
  87. icon: {
  88. type: String,
  89. default: 'checkmark'
  90. },
  91. // step的排列方向,row-横向,column-竖向
  92. direction: {
  93. type: String,
  94. default: 'row'
  95. }
  96. },
  97. data() {
  98. return {};
  99. },
  100. };
  101. </script>
  102. <style lang="scss" scoped>
  103. @import '../../libs/css/style.components.scss';
  104. $u-steps-item-number-width: 44rpx;
  105. $u-steps-item-dot-width: 20rpx;
  106. .u-steps {
  107. @include vue-flex;
  108. .u-steps__item__num {
  109. font-size: 15px;
  110. }
  111. .u-steps__item {
  112. flex: 1;
  113. text-align: center;
  114. position: relative;
  115. min-width: 100rpx;
  116. font-size: 26rpx;
  117. color: #8799a3;
  118. @include vue-flex;
  119. justify-content: center;
  120. flex-direction: column;
  121. align-items: center;
  122. &--row {
  123. @include vue-flex;
  124. flex-direction: column;
  125. .u-steps__item__line {
  126. position: absolute;
  127. z-index: 0;
  128. left: 75%;
  129. width: 50%;
  130. &--dot {
  131. top: calc(#{$u-steps-item-dot-width} / 2);
  132. }
  133. &--number {
  134. top: calc(#{$u-steps-item-number-width} / 2);
  135. }
  136. }
  137. }
  138. &--column {
  139. @include vue-flex;
  140. flex-direction: row;
  141. justify-content: flex-start;
  142. align-items: baseline;
  143. min-height: 120rpx;
  144. .u-steps__item__line {
  145. position: absolute;
  146. z-index: 0;
  147. height: calc(100% - 25px);
  148. top: 17px;
  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: 20rpx;
  178. }
  179. }
  180. }
  181. .pathTraceColor {
  182. font-size: 15px;
  183. color: #333;
  184. }
  185. .active {
  186. font-size: 12px;
  187. color: rgba(51, 51, 51, 0.8);
  188. }
  189. </style>