uni-steps.vue 7.4 KB

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