uni-steps.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <view class="uni-steps">
  3. <view class="uni-steps-items" :class="'uni-steps-' + direction">
  4. <view class="uni-steps-item" v-for="(item,index) in steps" :key="index" :class="[item.status ? 'uni-steps-' + item.status : '']">
  5. <view class="uni-steps-item-title-container" :style="{color:item.status === 'process' ? activeColor : ''}">
  6. <view class="uni-steps-item-title">{{ item.title }}</view>
  7. <view class="uni-steps-item-desc" v-if="item.desc">{{ item.desc}}</view>
  8. </view>
  9. <view class="uni-steps-item-circle-container">
  10. <view class="uni-steps-item-circle" v-if="item.status !== 'process'" :style="{backgroundColor:item.status === 'finish' ? activeColor : ''}"></view>
  11. <uni-icon v-else type="checkbox-filled" size="14" :color="activeColor"></uni-icon>
  12. </view>
  13. <view class="uni-steps-item-line" v-if="index !== steps.length-1" :style="{backgroundColor:item.status === 'finish' ? activeColor : ''}"></view>
  14. </view>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. import uniIcon from '../uni-icon/uni-icon.vue'
  20. export default {
  21. name: "uni-steps",
  22. components: {
  23. uniIcon
  24. },
  25. props: {
  26. direction: { //排列方向 row column
  27. type: String,
  28. default: 'row'
  29. },
  30. activeColor: { //激活状态颜色
  31. type: String,
  32. default: '#1aad19'
  33. },
  34. active: { //当前步骤
  35. type: [Number, String],
  36. default: 0
  37. },
  38. data: Array //数据
  39. },
  40. data() {
  41. return {}
  42. },
  43. computed: {
  44. steps() {
  45. let steps = []
  46. this.data.forEach((item, index) => {
  47. let step = {}
  48. step.title = item.title
  49. step.desc = item.desc
  50. step.status = this.getStatus(index)
  51. steps.push(step)
  52. })
  53. return steps
  54. }
  55. },
  56. methods: {
  57. getStatus(index) {
  58. if (index < Number(this.active)) {
  59. return 'finish'
  60. } else if (index === Number(this.active)) {
  61. return 'process'
  62. }
  63. return ''
  64. }
  65. }
  66. }
  67. </script>
  68. <style lang="scss">
  69. $steps-line-color:#ebedf0;
  70. $steps-text-color:#969799;
  71. $steps-title-size:28upx;
  72. $steps-desc-size:24upx;
  73. $steps-text-finish-color:#333333;
  74. $steps-bg-color:#ffffff;
  75. .uni-steps {
  76. width: 100%;
  77. box-sizing: border-box;
  78. display: flex;
  79. flex-direction: column;
  80. overflow: hidden;
  81. position: relative;
  82. &-items {
  83. position: relative;
  84. display: flex;
  85. flex-direction: row;
  86. margin: 10px;
  87. box-sizing: border-box;
  88. overflow: hidden;
  89. &.uni-steps-column {
  90. margin: 10px 0;
  91. padding-left: 31px;
  92. flex-direction: column;
  93. .uni-steps-item {
  94. &:after {
  95. content: ' ';
  96. position: absolute;
  97. height: 1px;
  98. width: 100%;
  99. bottom: 9px;
  100. left: 0;
  101. background-color: #ebedf0;
  102. transform: scaleY(0.5);
  103. }
  104. &:last-child {
  105. position: relative;
  106. &:after {
  107. height: 0px;
  108. }
  109. .uni-steps-item-title-container {
  110. text-align: left;
  111. }
  112. .uni-steps-item-circle-container {
  113. left: -17px;
  114. right: auto
  115. }
  116. }
  117. &-title-container {
  118. transform: none;
  119. display: block;
  120. line-height: 36upx;
  121. }
  122. &-title {
  123. text-overflow: ellipsis;
  124. //white-space: nowrap;
  125. overflow: hidden;
  126. }
  127. &-desc {
  128. white-space: normal;
  129. display: -webkit-box;
  130. -webkit-box-orient: vertical;
  131. -webkit-line-clamp: 2;
  132. overflow: hidden;
  133. }
  134. &-circle-container {
  135. left: -17px;
  136. top: -1px;
  137. bottom: auto;
  138. padding: 8px 0px;
  139. z-index: 1;
  140. }
  141. &-line {
  142. height: 100%;
  143. width: 1px;
  144. left: -15px;
  145. top: -1px;
  146. bottom: auto;
  147. }
  148. &.uni-steps-process {
  149. .uni-steps-item-circle-container {
  150. bottom: auto;
  151. left: -21px;
  152. }
  153. }
  154. }
  155. }
  156. }
  157. &-item {
  158. flex: 1;
  159. position: relative;
  160. padding-bottom: 18px;
  161. &-title-container {
  162. text-align: left;
  163. margin-left: 3px;
  164. display: inline-block;
  165. transform: translateX(-50%);
  166. color: $steps-text-color;
  167. }
  168. &-title {
  169. font-size: $steps-title-size;
  170. }
  171. &-desc {
  172. font-size: $steps-desc-size;
  173. }
  174. &:first-child {
  175. .uni-steps-item-title-container {
  176. transform: none;
  177. margin-left: 0;
  178. }
  179. }
  180. &:last-child {
  181. position: absolute;
  182. right: 0;
  183. .uni-steps-item-title-container {
  184. transform: none;
  185. text-align: right;
  186. }
  187. .uni-steps-item-circle-container {
  188. left: auto;
  189. right: -8px
  190. }
  191. }
  192. &-circle-container {
  193. position: absolute;
  194. bottom: 8px;
  195. left: -8px;
  196. padding: 0 8px;
  197. background-color: $steps-bg-color;
  198. z-index: 1;
  199. }
  200. &-circle {
  201. width: 5px;
  202. height: 5px;
  203. background-color: $steps-text-color;
  204. border-radius: 50%;
  205. }
  206. &-line {
  207. background-color: $steps-line-color;
  208. position: absolute;
  209. bottom: 10px;
  210. left: 0;
  211. width: 100%;
  212. height: 1px;
  213. }
  214. &.uni-steps-finish {
  215. .uni-steps-item-title-container {
  216. color: $steps-text-finish-color;
  217. }
  218. }
  219. &.uni-steps-process {
  220. .uni-steps-item-circle-container {
  221. bottom: 3px;
  222. display: flex;
  223. }
  224. }
  225. }
  226. }
  227. </style>