tui-steps.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <template>
  2. <view class="tui-steps-box" :class="{ 'tui-steps-column': direction === 'column' }">
  3. <view
  4. class="tui-step-item"
  5. :style="{ width: direction === 'column' ? '100%' : spacing }"
  6. :class="[direction === 'row' ? 'tui-step-horizontal' : 'tui-step-vertical']"
  7. v-for="(item, index) in items"
  8. :key="index"
  9. @tap.stop="handleClick(index)"
  10. >
  11. <view class="tui-step-item-ico" :style="{ width: direction === 'column' ? '36rpx' : '100%' }">
  12. <view
  13. v-if="!item.name && !item.icon"
  14. class="tui-step-ico"
  15. :class="[direction === 'column' ? 'tui-step-column_ico' : 'tui-step-row_ico']"
  16. :style="{
  17. width: type == 2 || activeSteps === index ? '36rpx' : '16rpx',
  18. height: type == 2 || activeSteps === index ? '36rpx' : '16rpx',
  19. backgroundColor: index <= activeSteps ? activeColor : type == 2 ? '#fff' : deactiveColor,
  20. borderColor: index <= activeSteps ? activeColor : deactiveColor
  21. }"
  22. >
  23. <text v-if="activeSteps !== index" :style="{ color: index <= activeSteps ? '#fff' : '' }">{{ type == 1 ? '' : index + 1 }}</text>
  24. <tui-icon name="check" :size="16" color="#fff" v-if="activeSteps === index"></tui-icon>
  25. </view>
  26. <view class="tui-step-custom" :style="{ backgroundColor: backgroundColor }" v-if="item.name || item.icon">
  27. <tui-icon :name="item.name" :size="20" :color="index <= activeSteps ? activeColor : deactiveColor" v-if="item.name"></tui-icon>
  28. <image :src="index <= activeSteps ? item.activeIcon : item.icon" class="tui-step-img" mode="widthFix" v-if="!item.name"></image>
  29. </view>
  30. <view
  31. class="tui-step-line"
  32. :class="['tui-step-' + direction + '_line', direction == 'column' && (item.name || item.icon) ? 'tui-custom-left' : '']"
  33. :style="{
  34. borderColor: index <= activeSteps - 1 ? activeColor : deactiveColor,
  35. borderRightStyle: direction == 'column' ? lineStyle : '',
  36. borderTopStyle: direction == 'column' ? '' : lineStyle
  37. }"
  38. v-if="index != items.length - 1"
  39. ></view>
  40. </view>
  41. <view class="tui-step-item-main" :class="['tui-step-' + direction + '_item_main']">
  42. <view
  43. class="tui-step-item-title"
  44. :style="{
  45. color: index <= activeSteps ? activeColor : deactiveColor,
  46. fontSize: titleSize + 'rpx',
  47. lineHeight: titleSize + 'rpx',
  48. fontWeight: bold ? 'bold' : 'normal'
  49. }"
  50. >
  51. {{ item.title }}
  52. </view>
  53. <view class="tui-step-item-content" :style="{ color: index <= activeSteps ? activeColor : deactiveColor, fontSize: descSize + 'rpx' }">{{ item.desc }}</view>
  54. </view>
  55. </view>
  56. </view>
  57. </template>
  58. <script>
  59. //如果自定义传入图标内容,则需要拆分组件
  60. export default {
  61. name: 'tuiSteps',
  62. props: {
  63. // 1-默认步骤 2-数字步骤
  64. type: {
  65. type: Number,
  66. default: 1
  67. },
  68. spacing: {
  69. type: String,
  70. default: '160rpx'
  71. },
  72. // 方向 row column
  73. direction: {
  74. type: String,
  75. default: 'row'
  76. },
  77. // 激活状态成功颜色
  78. activeColor: {
  79. type: String,
  80. default: '#5677fc'
  81. },
  82. // 未激活状态颜色
  83. deactiveColor: {
  84. type: String,
  85. default: '#999999'
  86. },
  87. //title字体大小
  88. titleSize: {
  89. type: Number,
  90. default: 28
  91. },
  92. //title是否粗体
  93. bold: {
  94. type: Boolean,
  95. default: false
  96. },
  97. //desc字体大小
  98. descSize: {
  99. type: Number,
  100. default: 24
  101. },
  102. // 当前步骤
  103. activeSteps: {
  104. type: Number,
  105. default: -1
  106. },
  107. //线条样式 同border线条样式
  108. lineStyle: {
  109. type: String,
  110. default: 'solid'
  111. },
  112. /**
  113. * [{
  114. title: "标题",
  115. desc: "描述",
  116. name:"字体图标 thorui icon内",
  117. icon:"图片图标",
  118. activeIcon:"已完成步骤显示图片图标"
  119. }]
  120. * */
  121. items: {
  122. type: Array,
  123. default() {
  124. return [];
  125. }
  126. },
  127. //自定义item内容时背景色
  128. backgroundColor: {
  129. type: String,
  130. default: '#fff'
  131. }
  132. },
  133. data() {
  134. return {};
  135. },
  136. methods: {
  137. handleClick(index) {
  138. this.$emit('click', { index: index });
  139. }
  140. }
  141. };
  142. </script>
  143. <style scoped>
  144. .tui-steps-box {
  145. width: 100%;
  146. display: flex;
  147. justify-content: center;
  148. }
  149. .tui-steps-column {
  150. flex-direction: column;
  151. }
  152. .tui-step-ico {
  153. border-radius: 80rpx;
  154. position: relative;
  155. z-index: 3;
  156. margin: 0 auto;
  157. border-width: 1rpx;
  158. border-style: solid;
  159. display: flex;
  160. align-items: center;
  161. justify-content: center;
  162. }
  163. .tui-step-row_ico {
  164. top: 50%;
  165. transform: translateY(-50%);
  166. }
  167. .tui-step-column_ico {
  168. top: 0;
  169. }
  170. .tui-step-line {
  171. position: absolute;
  172. left: 50%;
  173. top: 20rpx;
  174. width: 100%;
  175. height: 0rpx;
  176. border-top-width: 1rpx;
  177. z-index: 2;
  178. }
  179. .tui-step-row_item_main {
  180. text-align: center;
  181. }
  182. .tui-step-item {
  183. font-size: 24rpx;
  184. position: relative;
  185. box-sizing: border-box;
  186. }
  187. .tui-step-item-ico {
  188. height: 36rpx;
  189. line-height: 36rpx;
  190. text-align: center;
  191. }
  192. .tui-step-custom {
  193. display: flex;
  194. align-items: center;
  195. justify-content: center;
  196. width: 48rpx;
  197. height: 40rpx;
  198. position: relative;
  199. z-index: 4;
  200. margin: 0 auto;
  201. }
  202. .tui-step-img {
  203. width: 40rpx;
  204. height: 40rpx;
  205. }
  206. .tui-step-item-main {
  207. margin-top: 16rpx;
  208. clear: both;
  209. }
  210. .tui-step-item-title {
  211. word-break: break-all;
  212. }
  213. .tui-step-item-content {
  214. margin-top: 8rpx;
  215. word-break: break-all;
  216. }
  217. .tui-step-vertical {
  218. width: 100%;
  219. display: flex;
  220. padding-bottom: 60rpx;
  221. }
  222. .tui-step-column_item_main {
  223. margin-top: 0;
  224. padding-left: 20rpx;
  225. }
  226. .tui-step-column_line {
  227. position: absolute;
  228. height: 100%;
  229. top: 0;
  230. left: 18rpx;
  231. margin: 0;
  232. width: 0rpx;
  233. border-right-width: 1rpx;
  234. }
  235. .tui-custom-left {
  236. left: 20rpx !important;
  237. }
  238. </style>