my-steps.vue 6.8 KB

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