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