u-steps.vue 2.2 KB

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