uni-steps.vue 6.6 KB

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