DivisionTestStepper.vue
2.87 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<template>
<div class="division-test-stepper">
<div class="stepper-track">
<template v-for="n in 3">
<button
:key="'node-' + n"
type="button"
class="stepper-node"
:class="'is-' + stepVisualState(n)"
@click="onStepClick(n)"
>
<i v-if="stepVisualState(n) === 'done'" class="el-icon-check stepper-check" />
<span v-else class="stepper-num">{{ n }}</span>
</button>
<div
v-if="n < 3"
:key="'line-' + n"
class="stepper-line"
:class="{ 'is-done': isConnectorDone(n) }"
/>
</template>
</div>
</div>
</template>
<script>
export default {
name: 'DivisionTestStepper',
props: {
maxReachedStep: {
type: Number,
default: 1
},
viewStep: {
type: Number,
default: 1
},
stepCompletedFlags: {
type: Array,
default: () => [false, false, false]
}
},
methods: {
/** done=蓝色勾 | current=蓝色序号 | wait=灰色序号 */
stepVisualState(stepNum) {
const idx = stepNum - 1
const completed =
!!this.stepCompletedFlags[idx] || stepNum < Number(this.viewStep)
if (completed) return 'done'
if (stepNum === Number(this.viewStep)) return 'current'
return 'wait'
},
/** 步骤 n 与 n+1 之间的连线:前序步骤已完成时为蓝色 */
isConnectorDone(stepNum) {
return this.stepVisualState(stepNum) === 'done'
},
onStepClick(stepNum) {
this.$emit('step-click', stepNum)
}
}
}
</script>
<style scoped lang="scss">
$step-primary: #2a58ad;
$step-wait-border: #dcdfe6;
$step-wait-text: #c0c4cc;
$step-line-wait: #dcdfe6;
.division-test-stepper {
margin-bottom: 24px;
padding: 0 40px;
}
.stepper-track {
display: flex;
align-items: center;
justify-content: center;
max-width: 360px;
margin: 0 auto;
}
.stepper-node {
flex-shrink: 0;
display: inline-flex;
align-items: center;
justify-content: center;
width: 28px;
height: 28px;
padding: 0;
border-radius: 50%;
border: 1px solid $step-wait-border;
background: #fff;
cursor: pointer;
outline: none;
cursor: pointer;
transition: border-color 0.2s, color 0.2s;
&:focus-visible {
box-shadow: 0 0 0 2px rgba($step-primary, 0.25);
}
&.is-done {
border-color: $step-primary;
color: $step-primary;
}
&.is-current {
border-color: $step-primary;
color: $step-primary;
}
&.is-wait {
border-color: $step-wait-border;
color: $step-wait-text;
}
}
.stepper-check {
font-size: 14px;
font-weight: 700;
line-height: 1;
}
.stepper-num {
font-size: 14px;
font-weight: 500;
line-height: 1;
}
.stepper-line {
flex: 1;
height: 1px;
min-width: 48px;
margin: 0 8px;
background: $step-line-wait;
transition: background-color 0.2s;
&.is-done {
background: $step-primary;
}
}
</style>