You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.2 KiB

4 months ago
  1. <template>
  2. <view
  3. class="u-steps"
  4. :class="[`u-steps--${direction}`]"
  5. >
  6. <slot></slot>
  7. </view>
  8. </template>
  9. <script>
  10. import { props } from './props';
  11. import { mpMixin } from '../../libs/mixin/mpMixin';
  12. import { mixin } from '../../libs/mixin/mixin';
  13. import test from '../../libs/function/test';
  14. /**
  15. * Steps 步骤条
  16. * @description 该组件一般用于完成一个任务要分几个步骤标识目前处于第几步的场景
  17. * @tutorial https://uview-plus.jiangruyi.com/components/steps.html
  18. * @property {String} direction row-横向column-竖向 (默认 'row' )
  19. * @property {String | Number} current 设置当前处于第几步 (默认 0 )
  20. * @property {String} activeColor 激活状态颜色 (默认 '#3c9cff' )
  21. * @property {String} inactiveColor 未激活状态颜色 (默认 '#969799' )
  22. * @property {String} activeIcon 激活状态的图标
  23. * @property {String} inactiveIcon 未激活状态图标
  24. * @property {Boolean} dot 是否显示点类型 (默认 false )
  25. * @example <u-steps current="0"><u-steps-item title="已出库" desc="10:35" ></u-steps-item></u-steps>
  26. */
  27. export default {
  28. name: 'u-steps',
  29. mixins: [mpMixin, mixin, props],
  30. data() {
  31. return {
  32. }
  33. },
  34. watch: {
  35. children() {
  36. this.updateChildData()
  37. },
  38. parentData() {
  39. this.updateChildData()
  40. }
  41. },
  42. computed: {
  43. // 监听参数的变化,通过watch中,手动去更新子组件的数据,否则子组件不会自动变化
  44. parentData() {
  45. return [this.current, this.direction, this.activeColor, this.inactiveColor, this.activeIcon, this.inactiveIcon, this.dot]
  46. }
  47. },
  48. methods: {
  49. // 更新子组件的数据
  50. updateChildData() {
  51. this.children.map(child => {
  52. // 先判断子组件是否存在对应的方法
  53. test.func((child || {}).updateFromParent()) && child.updateFromParent()
  54. })
  55. },
  56. // 接受子组件的通知,去修改其他子组件的数据
  57. updateFromChild() {
  58. this.updateChildData()
  59. }
  60. },
  61. created() {
  62. this.children = []
  63. }
  64. }
  65. </script>
  66. <style lang="scss" scoped>
  67. @import "../../libs/css/components.scss";
  68. .u-steps {
  69. @include flex;
  70. &--column {
  71. flex-direction: column
  72. }
  73. &--row {
  74. flex-direction: row;
  75. flex: 1;
  76. }
  77. }
  78. </style>