uni-steps.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <view class="uni-steps">
  3. <view :class="'uni-steps-' + direction" class="uni-steps-items">
  4. <view v-for="(item,index) in options" :key="index" :class="{'uni-steps-process':index === active,'uni-steps-finish':index < active}" class="uni-steps-item">
  5. <view :style="{color:index === active ? activeColor : ''}" class="uni-steps-item-title-container">
  6. <view class="uni-steps-item-title">{{ item.title }}</view>
  7. <view v-if="item.desc" class="uni-steps-item-desc">{{ item.desc }}</view>
  8. </view>
  9. <view class="uni-steps-item-circle-container">
  10. <view v-if="index !== active" :style="{backgroundColor:index < active ? activeColor : ''}" class="uni-steps-item-circle" />
  11. <uni-icon v-else :color="activeColor" type="checkbox-filled" size="14" />
  12. </view>
  13. <view v-if="index !== options.length-1" :style="{backgroundColor:index < active ? activeColor : ''}" class="uni-steps-item-line" />
  14. </view>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. import uniIcon from '../uni-icon/uni-icon.vue'
  20. export default {
  21. name: 'UniSteps',
  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,
  36. default: 0
  37. },
  38. options: {
  39. type: Array,
  40. default () {
  41. return []
  42. }
  43. } // 数据
  44. },
  45. data() {
  46. return {}
  47. }
  48. }
  49. </script>
  50. <style>
  51. @charset "UTF-8";
  52. .uni-steps {
  53. width: 100%;
  54. box-sizing: border-box;
  55. display: flex;
  56. flex-direction: column;
  57. overflow: hidden;
  58. position: relative
  59. }
  60. .uni-steps-items {
  61. position: relative;
  62. display: flex;
  63. flex-direction: row;
  64. margin: 10px;
  65. box-sizing: border-box;
  66. overflow: hidden
  67. }
  68. .uni-steps-items.uni-steps-column {
  69. margin: 10px 0;
  70. padding-left: 31px;
  71. flex-direction: column
  72. }
  73. .uni-steps-items.uni-steps-column .uni-steps-item:after {
  74. content: ' ';
  75. position: absolute;
  76. height: 1px;
  77. width: 100%;
  78. bottom: 9px;
  79. left: 0;
  80. background-color: #ebedf0;
  81. transform: scaleY(.5)
  82. }
  83. .uni-steps-items.uni-steps-column .uni-steps-item:last-child {
  84. position: relative
  85. }
  86. .uni-steps-items.uni-steps-column .uni-steps-item:last-child:after {
  87. height: 0
  88. }
  89. .uni-steps-items.uni-steps-column .uni-steps-item:last-child .uni-steps-item-title-container {
  90. text-align: left
  91. }
  92. .uni-steps-items.uni-steps-column .uni-steps-item:last-child .uni-steps-item-circle-container {
  93. left: -17px;
  94. right: auto
  95. }
  96. .uni-steps-items.uni-steps-column .uni-steps-item-title-container {
  97. transform: none;
  98. display: block;
  99. line-height: 36upx
  100. }
  101. .uni-steps-items.uni-steps-column .uni-steps-item-title {
  102. text-overflow: ellipsis;
  103. white-space: nowrap;
  104. overflow: hidden
  105. }
  106. .uni-steps-items.uni-steps-column .uni-steps-item-desc {
  107. white-space: normal;
  108. display: -webkit-box;
  109. -webkit-box-orient: vertical;
  110. -webkit-line-clamp: 2;
  111. overflow: hidden
  112. }
  113. .uni-steps-items.uni-steps-column .uni-steps-item-circle-container {
  114. left: -17px;
  115. top: -1px;
  116. bottom: auto;
  117. padding: 8px 0;
  118. z-index: 1
  119. }
  120. .uni-steps-items.uni-steps-column .uni-steps-item-line {
  121. height: 100%;
  122. width: 1px;
  123. left: -15px;
  124. top: -1px;
  125. bottom: auto
  126. }
  127. .uni-steps-items.uni-steps-column .uni-steps-item.uni-steps-process .uni-steps-item-circle-container {
  128. bottom: auto;
  129. left: -21px
  130. }
  131. .uni-steps-item {
  132. flex: 1;
  133. position: relative;
  134. padding-bottom: 18px
  135. }
  136. .uni-steps-item-title-container {
  137. text-align: left;
  138. margin-left: 3px;
  139. display: inline-block;
  140. transform: translateX(-50%);
  141. color: #999
  142. }
  143. .uni-steps-item-title {
  144. font-size: 28upx
  145. }
  146. .uni-steps-item-desc {
  147. font-size: 24upx
  148. }
  149. .uni-steps-item:first-child .uni-steps-item-title-container {
  150. transform: none;
  151. margin-left: 0
  152. }
  153. .uni-steps-item:last-child {
  154. position: absolute;
  155. right: 0
  156. }
  157. .uni-steps-item:last-child .uni-steps-item-title-container {
  158. transform: none;
  159. text-align: right
  160. }
  161. .uni-steps-item:last-child .uni-steps-item-circle-container {
  162. left: auto;
  163. right: -8px
  164. }
  165. .uni-steps-item-circle-container {
  166. position: absolute;
  167. bottom: 8px;
  168. left: -8px;
  169. padding: 0 8px;
  170. background-color: #fff;
  171. z-index: 1
  172. }
  173. .uni-steps-item-circle {
  174. width: 5px;
  175. height: 5px;
  176. background-color: #999;
  177. border-radius: 50%
  178. }
  179. .uni-steps-item-line {
  180. background-color: #ebedf0;
  181. position: absolute;
  182. bottom: 10px;
  183. left: 0;
  184. width: 100%;
  185. height: 1px
  186. }
  187. .uni-steps-item.uni-steps-finish .uni-steps-item-title-container {
  188. color: #333
  189. }
  190. .uni-steps-item.uni-steps-process .uni-steps-item-circle-container {
  191. bottom: 3px;
  192. display: flex
  193. }
  194. </style>