uni-steps.vue 5.8 KB

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