step.vue
2.99 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<template>
<div :class="wrapClasses" :style="styles">
<div :class="[prefixCls + '-tail']"><i></i></div>
<div :class="[prefixCls + '-head']">
<div :class="[prefixCls + '-head-inner']">
<span v-if="!icon && currentStatus != 'finish' && currentStatus != 'error'">{{ stepNumber }}</span>
<span v-else :class="iconClasses"></span>
</div>
</div>
<div :class="[prefixCls + '-main']">
<div :class="[prefixCls + '-title']">{{ title }}</div>
<slot>
<div v-if="content" :class="[prefixCls + '-content']">{{ content }}</div>
</slot>
</div>
</div>
</template>
<script>
import { oneOf } from '../../utils/assist';
const prefixCls = 'ivu-steps';
const iconPrefixCls = 'ivu-icon';
export default {
name: 'Step',
props: {
status: {
validator (value) {
return oneOf(value, ['wait', 'process', 'finish', 'error']);
}
},
title: {
type: String,
default: ''
},
content: {
type: String
},
icon: {
type: String
}
},
data () {
return {
prefixCls: prefixCls,
stepNumber: '',
nextError: false,
total: 1,
currentStatus: ''
};
},
created () {
this.currentStatus = this.status;
},
computed: {
wrapClasses () {
return [
`${prefixCls}-item`,
`${prefixCls}-status-${this.currentStatus}`,
{
[`${prefixCls}-custom`]: !!this.icon,
[`${prefixCls}-next-error`]: this.nextError
}
];
},
iconClasses () {
let icon = '';
if (this.icon) {
icon = this.icon;
} else {
if (this.currentStatus == 'finish') {
icon = 'ios-checkmark-empty';
} else if (this.currentStatus == 'error') {
icon = 'ios-close-empty';
}
}
return [
`${prefixCls}-icon`,
`${iconPrefixCls}`,
{
[`${iconPrefixCls}-${icon}`]: icon != ''
}
];
},
styles () {
return {
width: `${1/this.total*100}%`
};
}
},
watch: {
status (val) {
this.currentStatus = val;
if (this.currentStatus == 'error') {
this.$parent.setNextError();
}
}
}
};
</script>