uni-steps.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <view class="uni-steps">
  3. <view :class="[direction==='column'?'uni-steps__column':'uni-steps__row']">
  4. <view :class="[direction==='column'?'uni-steps__column-text-container':'uni-steps__row-text-container']">
  5. <view v-for="(item,index) in options" :key="index" :class="[direction==='column'?'uni-steps__column-text':'uni-steps__row-text']">
  6. <text :style="{color:index<=active?activeColor:deactiveColor}" :class="[direction==='column'?'uni-steps__column-title':'uni-steps__row-title']">{{item.title}}</text>
  7. <text :style="{color:index<=active?activeColor:deactiveColor}" :class="[direction==='column'?'uni-steps__column-desc':'uni-steps__row-desc']">{{item.desc}}</text>
  8. </view>
  9. </view>
  10. <view :class="[direction==='column'?'uni-steps__column-container':'uni-steps__row-container']">
  11. <view :class="[direction==='column'?'uni-steps__column-line-item':'uni-steps__row-line-item']" v-for="(item,index) in options"
  12. :key="index">
  13. <view :class="[direction==='column'?'uni-steps__column-line':'uni-steps__row-line',direction==='column'?'uni-steps__column-line--before':'uni-steps__row-line--before']"
  14. :style="{backgroundColor:index<=active&&index!==0?activeColor:index===0?'transparent':deactiveColor}"></view>
  15. <view :class="[direction==='column'?'uni-steps__column-check':'uni-steps__row-check']" v-if="index === active">
  16. <uni-icons :color="activeColor" type="checkbox-filled" size="14"></uni-icons>
  17. </view>
  18. <view :class="[direction==='column'?'uni-steps__column-circle':'uni-steps__row-circle']" v-else :style="{backgroundColor:index<active?activeColor:deactiveColor}"></view>
  19. <view :class="[direction==='column'?'uni-steps__column-line':'uni-steps__row-line',direction==='column'?'uni-steps__column-line--after':'uni-steps__row-line--after']"
  20. :style="{backgroundColor:index<active&&index!==options.length-1?activeColor:index===options.length-1?'transparent':deactiveColor}"></view>
  21. </view>
  22. </view>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. import uniIcons from '../uni-icons/uni-icons.vue'
  28. export default {
  29. name: 'UniSteps',
  30. components: {
  31. uniIcons
  32. },
  33. props: {
  34. direction: {
  35. // 排列方向 row column
  36. type: String,
  37. default: 'row'
  38. },
  39. activeColor: {
  40. // 激活状态颜色
  41. type: String,
  42. default: '#1aad19'
  43. },
  44. deactiveColor: {
  45. // 未激活状态颜色
  46. type: String,
  47. default: '#999999'
  48. },
  49. active: {
  50. // 当前步骤
  51. type: Number,
  52. default: 0
  53. },
  54. options: {
  55. type: Array,
  56. default () {
  57. return []
  58. }
  59. } // 数据
  60. },
  61. data() {
  62. return {}
  63. }
  64. }
  65. </script>
  66. <style lang="scss" scoped>
  67. .uni-steps {
  68. /* #ifndef APP-NVUE */
  69. display: flex;
  70. width: 100%;
  71. /* #endif */
  72. /* #ifdef APP-NVUE */
  73. flex: 1;
  74. /* #endif */
  75. flex-direction: column;
  76. }
  77. .uni-steps__row {
  78. /* #ifndef APP-NVUE */
  79. display: flex;
  80. /* #endif */
  81. flex-direction: column;
  82. }
  83. .uni-steps__column {
  84. /* #ifndef APP-NVUE */
  85. display: flex;
  86. /* #endif */
  87. flex-direction: row-reverse;
  88. }
  89. .uni-steps__row-text-container {
  90. /* #ifndef APP-NVUE */
  91. display: flex;
  92. /* #endif */
  93. flex-direction: row;
  94. }
  95. .uni-steps__column-text-container {
  96. /* #ifndef APP-NVUE */
  97. display: flex;
  98. /* #endif */
  99. flex-direction: column;
  100. flex: 1;
  101. }
  102. .uni-steps__row-text {
  103. /* #ifndef APP-NVUE */
  104. display: inline-flex;
  105. /* #endif */
  106. flex: 1;
  107. flex-direction: column;
  108. }
  109. .uni-steps__column-text {
  110. padding: 6px 0px;
  111. border-bottom-style: solid;
  112. border-bottom-width: 1px;
  113. border-bottom-color: $uni-border-color;
  114. /* #ifndef APP-NVUE */
  115. display: flex;
  116. /* #endif */
  117. flex-direction: column;
  118. }
  119. .uni-steps__row-title {
  120. font-size: $uni-font-size-base;
  121. line-height: 16px;
  122. text-align: center;
  123. }
  124. .uni-steps__column-title {
  125. font-size: $uni-font-size-base;
  126. text-align: left;
  127. line-height: 18px;
  128. }
  129. .uni-steps__row-desc {
  130. font-size: 12px;
  131. line-height: 14px;
  132. text-align: center;
  133. }
  134. .uni-steps__column-desc {
  135. font-size: $uni-font-size-sm;
  136. text-align: left;
  137. line-height: 18px;
  138. }
  139. .uni-steps__row-container {
  140. /* #ifndef APP-NVUE */
  141. display: flex;
  142. /* #endif */
  143. flex-direction: row;
  144. }
  145. .uni-steps__column-container {
  146. /* #ifndef APP-NVUE */
  147. display: inline-flex;
  148. /* #endif */
  149. width: 30px;
  150. flex-direction: column;
  151. }
  152. .uni-steps__row-line-item {
  153. /* #ifndef APP-NVUE */
  154. display: inline-flex;
  155. /* #endif */
  156. flex-direction: row;
  157. flex: 1;
  158. height: 14px;
  159. line-height: 14px;
  160. align-items: center;
  161. justify-content: center;
  162. }
  163. .uni-steps__column-line-item {
  164. /* #ifndef APP-NVUE */
  165. display: flex;
  166. /* #endif */
  167. flex-direction: column;
  168. flex: 1;
  169. align-items: center;
  170. justify-content: center;
  171. }
  172. .uni-steps__row-line {
  173. flex: 1;
  174. height: 1px;
  175. background-color: $uni-text-color-grey;
  176. }
  177. .uni-steps__column-line {
  178. width: 1px;
  179. background-color: $uni-text-color-grey;
  180. }
  181. .uni-steps__row-line--after {
  182. transform: translateX(1px);
  183. }
  184. .uni-steps__column-line--after {
  185. flex: 1;
  186. transform: translate(0px, 1px);
  187. }
  188. .uni-steps__row-line--before {
  189. transform: translateX(-1px);
  190. }
  191. .uni-steps__column-line--before {
  192. height: 6px;
  193. transform: translate(0px, -1px);
  194. }
  195. .uni-steps__row-circle {
  196. width: 5px;
  197. height: 5px;
  198. border-radius: 100px;
  199. background-color: $uni-text-color-grey;
  200. margin: 0px 3px;
  201. }
  202. .uni-steps__column-circle {
  203. width: 5px;
  204. height: 5px;
  205. border-radius: 100px;
  206. background-color: $uni-text-color-grey;
  207. margin: 4px 0px 5px 0px;
  208. }
  209. .uni-steps__row-check {
  210. margin: 0px 6px;
  211. }
  212. .uni-steps__column-check {
  213. height: 14px;
  214. line-height: 14px;
  215. margin: 2px 0px;
  216. }
  217. </style>