Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

353 linhas
8.5 KiB

  1. <template>
  2. <view class="u-steps-item" ref="u-steps-item" :class="[`u-steps-item--${parentData.direction}`]">
  3. <view class="u-steps-item__line" v-if="index + 1 < childLength"
  4. :class="[`u-steps-item__line--${parentData.direction}`]" :style="[lineStyle]"></view>
  5. <view class="u-steps-item__wrapper"
  6. :class="[`u-steps-item__wrapper--${parentData.direction}`, parentData.dot && `u-steps-item__wrapper--${parentData.direction}--dot`]"
  7. :style="[itemStyleInner]">
  8. <slot name="icon">
  9. <view class="u-steps-item__wrapper__dot" v-if="parentData.dot" :style="{
  10. backgroundColor: statusColor
  11. }">
  12. </view>
  13. <view class="u-steps-item__wrapper__icon" v-else-if="parentData.activeIcon || parentData.inactiveIcon">
  14. <up-icon :name="index <= parentData.current ? parentData.activeIcon : parentData.inactiveIcon"
  15. :size="iconSize"
  16. :color="index <= parentData.current ? parentData.activeColor : parentData.inactiveColor">
  17. </up-icon>
  18. </view>
  19. <view v-else :style="{
  20. backgroundColor: statusClass === 'process' ? parentData.activeColor : 'transparent',
  21. borderColor: statusColor
  22. }" class="u-steps-item__wrapper__circle">
  23. <text v-if="statusClass === 'process' || statusClass === 'wait'"
  24. class="u-steps-item__wrapper__circle__text" :style="{
  25. color: index == parentData.current ? activeStepTextColor : parentData.inactiveColor
  26. }">{{ index + 1}}</text>
  27. <up-icon v-else :color="statusClass === 'error' ? 'error' : parentData.activeColor" size="12"
  28. :name="statusClass === 'error' ? 'close' : 'checkmark'"></up-icon>
  29. </view>
  30. </slot>
  31. </view>
  32. <view class="u-steps-item__content" :class="[`u-steps-item__content--${parentData.direction}`,
  33. parentData.current == index ? 'u-steps-item__content--current' : '']"
  34. :style="[contentStyle]">
  35. <slot name="content" :index="index">
  36. </slot>
  37. <template v-if="!$slots['content']">
  38. <view class="u-steps-item__content__title">
  39. <slot name="title">
  40. </slot>
  41. <up-text v-if="!$slots['title']" :text="title" lineHeight="20px"
  42. :type="parentData.current == index ? 'main' : 'content'"
  43. :size="parentData.current == index ? 14 : 13"></up-text>
  44. </view>
  45. <view class="u-steps-item__content__desc">
  46. <slot name="desc">
  47. </slot>
  48. <up-text v-if="!$slots['desc']" :text="desc" type="tips" size="12"></up-text>
  49. </view>
  50. </template>
  51. </view>
  52. <!-- <view
  53. class="u-steps-item__line"
  54. v-if="showLine && parentData.direction === 'column'"
  55. :class="[`u-steps-item__line--${parentData.direction}`]"
  56. :style="[lineStyle]"
  57. ></view> -->
  58. </view>
  59. </template>
  60. <script>
  61. import { props } from './props';
  62. import { mpMixin } from '../../libs/mixin/mpMixin';
  63. import { mixin } from '../../libs/mixin/mixin';
  64. import { sleep, error } from '../../libs/function/index';
  65. import color from '../../libs/config/color';
  66. // #ifdef APP-NVUE
  67. const dom = uni.requireNativePlugin('dom')
  68. // #endif
  69. /**
  70. * StepsItem 步骤条的子组件
  71. * @description 本组件需要和u-steps配合使用
  72. * @tutorial https://uview-plus.jiangruyi.com/components/steps.html
  73. * @property {String} title 标题文字
  74. * @property {String} current 描述文本
  75. * @property {String | Number} iconSize 图标大小 (默认 17 )
  76. * @property {Boolean} error 当前步骤是否处于失败状态 (默认 false )
  77. * @example <u-steps current="0"><u-steps-item title="已出库" desc="10:35" ></u-steps-item></u-steps>
  78. */
  79. export default {
  80. name: 'u-steps-item',
  81. mixins: [mpMixin, mixin, props],
  82. data() {
  83. return {
  84. index: 0,
  85. childLength: 0,
  86. showLine: false,
  87. size: {
  88. height: 0,
  89. width: 0
  90. },
  91. parentData: {
  92. direction: 'row',
  93. current: 0,
  94. activeColor: '',
  95. inactiveColor: '',
  96. activeIcon: '',
  97. inactiveIcon: '',
  98. dot: false
  99. }
  100. }
  101. },
  102. watch: {
  103. 'parentData'(newValue, oldValue) {
  104. }
  105. },
  106. created() {
  107. this.init()
  108. },
  109. // #ifdef MP-TOUTIAO
  110. options: {
  111. virtualHost: false
  112. },
  113. // #endif
  114. computed: {
  115. lineStyle() {
  116. const style = {}
  117. if (this.parentData.direction === 'row') {
  118. style.width = this.size.width + 'px'
  119. style.left = this.size.width / 2 + 'px'
  120. } else {
  121. style.height = this.size.height + 'px'
  122. // style.top = this.size.height / 2 + 'px'
  123. }
  124. style.backgroundColor = this.parent.children?.[this.index + 1]?.error ? color.error : this.index <
  125. this
  126. .parentData
  127. .current ? this.parentData.activeColor : this.parentData.inactiveColor
  128. return style
  129. },
  130. itemStyleInner() {
  131. return {
  132. ...this.itemStyle
  133. }
  134. },
  135. statusClass() {
  136. const {
  137. index,
  138. error
  139. } = this
  140. const {
  141. current
  142. } = this.parentData
  143. if (current == index) {
  144. return error === true ? 'error' : 'process'
  145. } else if (error) {
  146. return 'error'
  147. } else if (current > index) {
  148. return 'finish'
  149. } else {
  150. return 'wait'
  151. }
  152. },
  153. statusColor() {
  154. let colorTmp = ''
  155. switch (this.statusClass) {
  156. case 'finish':
  157. colorTmp = this.parentData.activeColor
  158. break
  159. case 'error':
  160. colorTmp = color.error
  161. break
  162. case 'process':
  163. colorTmp = this.parentData.dot ? this.parentData.activeColor : 'transparent'
  164. break
  165. default:
  166. colorTmp = this.parentData.inactiveColor
  167. break
  168. }
  169. return colorTmp
  170. },
  171. contentStyle() {
  172. const style = {}
  173. if (this.parentData.direction === 'column') {
  174. style.marginLeft = this.parentData.dot ? '2px' : '6px'
  175. style.marginTop = this.parentData.dot ? '0px' : '6px'
  176. } else {
  177. style.marginTop = this.parentData.dot ? '2px' : '6px'
  178. style.marginLeft = this.parentData.dot ? '2px' : '6px'
  179. }
  180. return style
  181. },
  182. activeStepTextColor() {
  183. return this.upThemeVar('--up-white', '#ffffff')
  184. }
  185. },
  186. mounted() {
  187. this.parent && this.parent.updateFromChild()
  188. sleep().then(() => {
  189. this.getStepsItemRect()
  190. })
  191. },
  192. methods: {
  193. init() {
  194. // 初始化数据
  195. this.updateParentData()
  196. if (!this.parent) {
  197. return error('u-steps-item必须要搭配u-steps组件使用')
  198. }
  199. this.index = this.parent.children.indexOf(this)
  200. this.childLength = this.parent.children.length
  201. },
  202. updateParentData() {
  203. // 此方法在mixin中
  204. this.getParentData('u-steps')
  205. },
  206. // 父组件数据发生变化
  207. updateFromParent() {
  208. this.init()
  209. },
  210. // 获取组件的尺寸,用于设置横线的位置
  211. getStepsItemRect() {
  212. // #ifndef APP-NVUE
  213. this.$uGetRect('.u-steps-item').then(size => {
  214. this.size = size
  215. })
  216. // #endif
  217. // #ifdef APP-NVUE
  218. dom.getComponentRect(this.$refs['u-steps-item'], res => {
  219. const {
  220. size
  221. } = res
  222. this.size = size
  223. })
  224. // #endif
  225. }
  226. }
  227. }
  228. </script>
  229. <style lang="scss" scoped>
  230. .u-steps-item {
  231. flex: 1;
  232. @include flex;
  233. &--row {
  234. flex-direction: column;
  235. align-items: center;
  236. position: relative;
  237. }
  238. &--column {
  239. position: relative;
  240. flex-direction: row;
  241. justify-content: flex-start;
  242. padding-bottom: 5px;
  243. }
  244. &__wrapper {
  245. @include flex;
  246. justify-content: center;
  247. align-items: center;
  248. position: relative;
  249. background-color: var(--up-card-bg-color, #fff);
  250. border-radius: 50px;
  251. &--column {
  252. width: 20px;
  253. height: 20px;
  254. &--dot {
  255. height: 20px;
  256. width: 20px;
  257. }
  258. }
  259. &--row {
  260. width: 20px;
  261. height: 20px;
  262. &--dot {
  263. width: 20px;
  264. height: 20px;
  265. }
  266. }
  267. &__circle {
  268. width: 20px;
  269. height: 20px;
  270. /* #ifndef APP-NVUE */
  271. box-sizing: border-box;
  272. flex-shrink: 0;
  273. /* #endif */
  274. border-radius: 100px;
  275. border-width: 1px;
  276. border-color: $u-tips-color;
  277. border-style: solid;
  278. @include flex(row);
  279. align-items: center;
  280. justify-content: center;
  281. transition: background-color 0.3s;
  282. &__text {
  283. color: $u-tips-color;
  284. font-size: 11px;
  285. @include flex(row);
  286. align-items: center;
  287. justify-content: center;
  288. text-align: center;
  289. line-height: 11px;
  290. }
  291. }
  292. &__dot {
  293. width: 10px;
  294. height: 10px;
  295. border-radius: 100px;
  296. background-color: $u-content-color;
  297. }
  298. }
  299. &__content {
  300. @include flex;
  301. flex: 1;
  302. &__title {
  303. // #ifdef H5
  304. cursor: pointer;
  305. // #endif
  306. }
  307. &--row {
  308. flex-direction: column;
  309. align-items: center;
  310. }
  311. &--column {
  312. flex-direction: column;
  313. margin-left: 6px;
  314. }
  315. }
  316. &__line {
  317. position: absolute;
  318. background: $u-tips-color;
  319. &--row {
  320. top: 10px;
  321. height: 1px;
  322. }
  323. &--column {
  324. width: 1px;
  325. left: 10px;
  326. }
  327. }
  328. }
  329. </style>