uni-steps.vue 6.0 KB

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