Blame view

src/components/steps/steps.vue 3.59 KB
7fa943eb   梁灏   init
1
2
3
4
5
6
7
8
9
10
11
  <template>
      <div :class="classes">
          <slot></slot>
      </div>
  </template>
  <script>
      import { oneOf } from '../../utils/assist';
  
      const prefixCls = 'ivu-steps';
  
      export default {
34ee7b4a   梁灏   support Tree & ad...
12
          name: 'Steps',
7fa943eb   梁灏   init
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
          props: {
              current: {
                  type: Number,
                  default: 0
              },
              status: {
                  validator (value) {
                      return oneOf(value, ['wait', 'process', 'finish', 'error']);
                  },
                  default: 'process'
              },
              size: {
                  validator (value) {
                      return oneOf(value, ['small']);
                  }
              },
              direction: {
                  validator (value) {
                      return oneOf(value, ['horizontal', 'vertical']);
                  },
                  default: 'horizontal'
              }
          },
          computed: {
              classes () {
                  return [
                      `${prefixCls}`,
                      `${prefixCls}-${this.direction}`,
                      {
                          [`${prefixCls}-${this.size}`]: !!this.size
                      }
b0893113   jingsam   :art: add eslint
44
                  ];
7fa943eb   梁灏   init
45
46
              }
          },
bd596e7a   huixisheng   support Steps
47
          mounted () {
7fa943eb   梁灏   init
48
49
50
51
52
53
              this.updateChildProps(true);
              this.setNextError();
              this.updateCurrent(true);
          },
          methods: {
              updateChildProps (isInit) {
45b672ca   梁灏   add Steps UI
54
                  const total = this.$children.length;
7fa943eb   梁灏   init
55
56
57
                  this.$children.forEach((child, index) => {
                      child.stepNumber = index + 1;
  
45b672ca   梁灏   add Steps UI
58
59
60
61
                      if (this.direction === 'horizontal') {
                          child.total = total;
                      }
  
7fa943eb   梁灏   init
62
63
                      // 如果已存在status,且在初始化时,则略过
                      // todo 如果当前是error,在current改变时需要处理
b450b555   huixisheng   update Steps
64
                      if (!(isInit && child.currentStatus)) {
7fa943eb   梁灏   init
65
66
                          if (index == this.current) {
                              if (this.status != 'error') {
b450b555   huixisheng   update Steps
67
                                  child.currentStatus = 'process';
7fa943eb   梁灏   init
68
69
                              }
                          } else if (index < this.current) {
b450b555   huixisheng   update Steps
70
                              child.currentStatus = 'finish';
7fa943eb   梁灏   init
71
                          } else {
b450b555   huixisheng   update Steps
72
                              child.currentStatus = 'wait';
7fa943eb   梁灏   init
73
74
75
                          }
                      }
  
b450b555   huixisheng   update Steps
76
                      if (child.currentStatus != 'error' && index != 0) {
7fa943eb   梁灏   init
77
78
79
80
81
82
                          this.$children[index - 1].nextError = false;
                      }
                  });
              },
              setNextError () {
                  this.$children.forEach((child, index) => {
b450b555   huixisheng   update Steps
83
                      if (child.currentStatus == 'error' && index != 0) {
7fa943eb   梁灏   init
84
85
86
87
88
                          this.$children[index - 1].nextError = true;
                      }
                  });
              },
              updateCurrent (isInit) {
b450b555   huixisheng   update Steps
89
90
91
92
                  // 防止溢出边界
                  if (this.current < 0 || this.current >= this.$children.length ) {
                      return;
                  }
7fa943eb   梁灏   init
93
                  if (isInit) {
b450b555   huixisheng   update Steps
94
                      const current_status = this.$children[this.current].currentStatus;
7fa943eb   梁灏   init
95
                      if (!current_status) {
b450b555   huixisheng   update Steps
96
                          this.$children[this.current].currentStatus = this.status;
7fa943eb   梁灏   init
97
98
                      }
                  } else {
b450b555   huixisheng   update Steps
99
                      this.$children[this.current].currentStatus = this.status;
7fa943eb   梁灏   init
100
101
102
103
104
105
106
107
108
109
110
                  }
              }
          },
          watch: {
              current () {
                  this.updateChildProps();
              },
              status () {
                  this.updateCurrent();
              }
          }
b0893113   jingsam   :art: add eslint
111
112
      };
  </script>