u-steps.vue 2.1 KB

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