7fa943eb
梁灏
init
|
1
2
3
4
5
6
7
8
9
10
11
12
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
|
<template>
<div :class="classes">
<slot></slot>
</div>
</template>
<script>
import { oneOf } from '../../utils/assist';
const prefixCls = 'ivu-steps';
export default {
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
add eslint
|
43
|
];
|
7fa943eb
梁灏
init
|
44
45
|
}
},
|
bd596e7a
huixisheng
support Steps
|
46
|
mounted () {
|
7fa943eb
梁灏
init
|
47
48
49
50
51
52
|
this.updateChildProps(true);
this.setNextError();
this.updateCurrent(true);
},
methods: {
updateChildProps (isInit) {
|
45b672ca
梁灏
add Steps UI
|
53
|
const total = this.$children.length;
|
7fa943eb
梁灏
init
|
54
55
56
|
this.$children.forEach((child, index) => {
child.stepNumber = index + 1;
|
45b672ca
梁灏
add Steps UI
|
57
58
59
60
|
if (this.direction === 'horizontal') {
child.total = total;
}
|
7fa943eb
梁灏
init
|
61
62
|
// 如果已存在status,且在初始化时,则略过
// todo 如果当前是error,在current改变时需要处理
|
b450b555
huixisheng
update Steps
|
63
|
if (!(isInit && child.currentStatus)) {
|
7fa943eb
梁灏
init
|
64
65
|
if (index == this.current) {
if (this.status != 'error') {
|
b450b555
huixisheng
update Steps
|
66
|
child.currentStatus = 'process';
|
7fa943eb
梁灏
init
|
67
68
|
}
} else if (index < this.current) {
|
b450b555
huixisheng
update Steps
|
69
|
child.currentStatus = 'finish';
|
7fa943eb
梁灏
init
|
70
|
} else {
|
b450b555
huixisheng
update Steps
|
71
|
child.currentStatus = 'wait';
|
7fa943eb
梁灏
init
|
72
73
74
|
}
}
|
b450b555
huixisheng
update Steps
|
75
|
if (child.currentStatus != 'error' && index != 0) {
|
7fa943eb
梁灏
init
|
76
77
78
79
80
81
|
this.$children[index - 1].nextError = false;
}
});
},
setNextError () {
this.$children.forEach((child, index) => {
|
b450b555
huixisheng
update Steps
|
82
|
if (child.currentStatus == 'error' && index != 0) {
|
7fa943eb
梁灏
init
|
83
84
85
86
87
|
this.$children[index - 1].nextError = true;
}
});
},
updateCurrent (isInit) {
|
b450b555
huixisheng
update Steps
|
88
89
90
91
|
// 防止溢出边界
if (this.current < 0 || this.current >= this.$children.length ) {
return;
}
|
7fa943eb
梁灏
init
|
92
|
if (isInit) {
|
b450b555
huixisheng
update Steps
|
93
|
const current_status = this.$children[this.current].currentStatus;
|
7fa943eb
梁灏
init
|
94
|
if (!current_status) {
|
b450b555
huixisheng
update Steps
|
95
|
this.$children[this.current].currentStatus = this.status;
|
7fa943eb
梁灏
init
|
96
97
|
}
} else {
|
b450b555
huixisheng
update Steps
|
98
|
this.$children[this.current].currentStatus = this.status;
|
7fa943eb
梁灏
init
|
99
100
101
102
103
104
105
106
107
108
109
|
}
}
},
watch: {
current () {
this.updateChildProps();
},
status () {
this.updateCurrent();
}
}
|
b0893113
jingsam
add eslint
|
110
111
|
};
</script>
|