steps.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <div class="nut-steps" :class="{horizontal: direction === 'horizontal'}">
  3. <slot></slot>
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. name: 'nut-steps',
  9. props: {
  10. current: {
  11. type: Number,
  12. default: 0
  13. },
  14. timeForward: {
  15. type: Boolean,
  16. default: false
  17. },
  18. direction: {
  19. type: String,
  20. default: 'vertical'
  21. },
  22. type: {
  23. type: String
  24. },
  25. source: {
  26. type: Array,
  27. default() {
  28. return [];
  29. }
  30. },
  31. },
  32. data() {
  33. return {
  34. steps: []
  35. };
  36. },
  37. methods: {
  38. updateChildProps(isInit) {
  39. const total = this.steps.length;
  40. this.steps.forEach((child, index) => {
  41. // 如果已存在status,且在初始化时,则略过
  42. // todo 如果当前是error,在current改变时需要处理
  43. if (!(isInit && child.currentStatus)) {
  44. if (this.current === index) {
  45. child.currentStatus = 'nut-step-status-process';
  46. }
  47. if (this.type === 'process') {
  48. if (index < this.current) {
  49. child.currentStatus = 'nut-step-status-finish';
  50. }
  51. if (index > this.current) {
  52. child.currentStatus = 'nut-step-status-wait';
  53. }
  54. }
  55. if (this.type === 'mini') {
  56. child.type = 'mini'
  57. }
  58. }
  59. if (index + 1 === total) {
  60. child.currentStatus += ' nut-step-last';
  61. }
  62. if (this.timeForward) {
  63. child.timeForward = true;
  64. }
  65. });
  66. },
  67. init() {
  68. if (this.$slots.default) {
  69. this.steps = this.$slots.default.filter(vnode => !!vnode.componentInstance).map(node => node.componentInstance);
  70. this.updateChildProps(true);
  71. }
  72. }
  73. },
  74. mounted() {
  75. this.init();
  76. },
  77. watch: {
  78. current() {
  79. this.updateChildProps();
  80. },
  81. source() {
  82. this.$nextTick(() => {
  83. this.init();
  84. });
  85. }
  86. }
  87. };
  88. </script>