Commit 85b0f07ed0beab38cacabbd137de2968255eccf3
Merge branch 'feature-steps' into feature-timeline
Showing
3 changed files
with
34 additions
and
21 deletions
Show diff stats
src/components/steps/step.vue
... | ... | @@ -3,7 +3,7 @@ |
3 | 3 | <div :class="[prefixCls + '-tail']"><i></i></div> |
4 | 4 | <div :class="[prefixCls + '-head']"> |
5 | 5 | <div :class="[prefixCls + '-head-inner']"> |
6 | - <span v-if="!icon && status != 'finish' && status != 'error'">{{ stepNumber }}</span> | |
6 | + <span v-if="!icon && currentStatus != 'finish' && currentStatus != 'error'">{{ stepNumber }}</span> | |
7 | 7 | <span v-else :class="iconClasses"></span> |
8 | 8 | </div> |
9 | 9 | </div> |
... | ... | @@ -21,11 +21,11 @@ |
21 | 21 | |
22 | 22 | export default { |
23 | 23 | props: { |
24 | - // status: { | |
25 | - // validator (value) { | |
26 | - // return oneOf(value, ['wait', 'process', 'finish', 'error']); | |
27 | - // } | |
28 | - // }, | |
24 | + status: { | |
25 | + validator (value) { | |
26 | + return oneOf(value, ['wait', 'process', 'finish', 'error']); | |
27 | + } | |
28 | + }, | |
29 | 29 | title: { |
30 | 30 | type: String, |
31 | 31 | default: '' |
... | ... | @@ -43,14 +43,17 @@ |
43 | 43 | stepNumber: '', |
44 | 44 | nextError: false, |
45 | 45 | total: 1, |
46 | - status: '' | |
46 | + currentStatus: '' | |
47 | 47 | }; |
48 | 48 | }, |
49 | + created () { | |
50 | + this.currentStatus = this.status; | |
51 | + }, | |
49 | 52 | computed: { |
50 | 53 | wrapClasses () { |
51 | 54 | return [ |
52 | 55 | `${prefixCls}-item`, |
53 | - `${prefixCls}-status-${this.status}`, | |
56 | + `${prefixCls}-status-${this.currentStatus}`, | |
54 | 57 | { |
55 | 58 | [`${prefixCls}-custom`]: !!this.icon, |
56 | 59 | [`${prefixCls}-next-error`]: this.nextError |
... | ... | @@ -63,9 +66,9 @@ |
63 | 66 | if (this.icon) { |
64 | 67 | icon = this.icon; |
65 | 68 | } else { |
66 | - if (this.status == 'finish') { | |
69 | + if (this.currentStatus == 'finish') { | |
67 | 70 | icon = 'ios-checkmark-empty'; |
68 | - } else if (this.status == 'error') { | |
71 | + } else if (this.currentStatus == 'error') { | |
69 | 72 | icon = 'ios-close-empty'; |
70 | 73 | } |
71 | 74 | } |
... | ... | @@ -85,8 +88,9 @@ |
85 | 88 | } |
86 | 89 | }, |
87 | 90 | watch: { |
88 | - status () { | |
89 | - if (this.status == 'error') { | |
91 | + status (val) { | |
92 | + this.currentStatus = val; | |
93 | + if (this.currentStatus == 'error') { | |
90 | 94 | this.$parent.setNextError(); |
91 | 95 | } |
92 | 96 | } | ... | ... |
src/components/steps/steps.vue
... | ... | @@ -60,38 +60,42 @@ |
60 | 60 | |
61 | 61 | // 如果已存在status,且在初始化时,则略过 |
62 | 62 | // todo 如果当前是error,在current改变时需要处理 |
63 | - if (!(isInit && child.status)) { | |
63 | + if (!(isInit && child.currentStatus)) { | |
64 | 64 | if (index == this.current) { |
65 | 65 | if (this.status != 'error') { |
66 | - child.status = 'process'; | |
66 | + child.currentStatus = 'process'; | |
67 | 67 | } |
68 | 68 | } else if (index < this.current) { |
69 | - child.status = 'finish'; | |
69 | + child.currentStatus = 'finish'; | |
70 | 70 | } else { |
71 | - child.status = 'wait'; | |
71 | + child.currentStatus = 'wait'; | |
72 | 72 | } |
73 | 73 | } |
74 | 74 | |
75 | - if (child.status != 'error' && index != 0) { | |
75 | + if (child.currentStatus != 'error' && index != 0) { | |
76 | 76 | this.$children[index - 1].nextError = false; |
77 | 77 | } |
78 | 78 | }); |
79 | 79 | }, |
80 | 80 | setNextError () { |
81 | 81 | this.$children.forEach((child, index) => { |
82 | - if (child.status == 'error' && index != 0) { | |
82 | + if (child.currentStatus == 'error' && index != 0) { | |
83 | 83 | this.$children[index - 1].nextError = true; |
84 | 84 | } |
85 | 85 | }); |
86 | 86 | }, |
87 | 87 | updateCurrent (isInit) { |
88 | + // 防止溢出边界 | |
89 | + if (this.current < 0 || this.current >= this.$children.length ) { | |
90 | + return; | |
91 | + } | |
88 | 92 | if (isInit) { |
89 | - const current_status = this.$children[this.current].status; | |
93 | + const current_status = this.$children[this.current].currentStatus; | |
90 | 94 | if (!current_status) { |
91 | - this.$children[this.current].status = this.status; | |
95 | + this.$children[this.current].currentStatus = this.status; | |
92 | 96 | } |
93 | 97 | } else { |
94 | - this.$children[this.current].status = this.status; | |
98 | + this.$children[this.current].currentStatus = this.status; | |
95 | 99 | } |
96 | 100 | } |
97 | 101 | }, | ... | ... |
test/routers/steps.vue
... | ... | @@ -31,6 +31,11 @@ |
31 | 31 | <Step title="上传头像" icon="camera" content="这里是该步骤的描述信息这里是该步骤的描述信息这里是该步骤的描述信息"></Step> |
32 | 32 | <Step title="验证邮箱" icon="email"></Step> |
33 | 33 | </Steps> |
34 | + <Steps :current="-1" direction="vertical"> | |
35 | + <Step title="注册" icon="person-add"></Step> | |
36 | + <Step title="上传头像" icon="camera" content="这里是该步骤的描述信息这里是该步骤的描述信息这里是该步骤的描述信息"></Step> | |
37 | + <Step title="验证邮箱" status="finish" icon="email"></Step> | |
38 | + </Steps> | |
34 | 39 | <br> |
35 | 40 | <p>当前正在进行第 {{ current + 1 }} 步</p> |
36 | 41 | <Steps :current="current"> | ... | ... |