u-steps.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. options: {
  65. virtualHost: false
  66. }
  67. }
  68. </script>
  69. <style lang="scss" scoped>
  70. @import "../../libs/css/components.scss";
  71. .u-steps {
  72. @include flex;
  73. &--column {
  74. flex-direction: column
  75. }
  76. &--row {
  77. flex-direction: row;
  78. flex: 1;
  79. /* #ifdef MP */
  80. display: grid;
  81. grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  82. /* #endif */
  83. }
  84. }
  85. </style>