ChangePassword.vue
3.93 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<template>
<div class="form-div">
<ElForm
:model=" verificationForm"
:rules="verificationRules"
size="medium"
class="login-form"
auto-complete="on"
label-position="left"
>
<template v-if="step === 1">
<ElFormItem>
<ElInput
v-model="verificationForm.phoneNum"
type="text"
placeholder="请输入用户名或手机号"
/>
</ElFormItem>
<div>
<PuzzleVerification
v-model="showPuzzle"
:style="{ display: showPuzzle ? 'block' : 'none' }"
block-type="puzzle"
:on-success="handleSuccess"
/>
</div>
</template>
<template v-if="step === 2">
<ElFormItem>
<ElInput
v-model="verificationForm.message"
type="text"
placeholder="请输入短信验证码"
>
<el-button slot="append">
发送验证码
</el-button>
</ElInput>
</ElFormItem>
</template>
<template v-if="step === 3">
<ElFormItem>
<ElInput
v-model=" verificationForm.password"
type="password"
name="password"
placeholder="请输入新密码"
/>
<ElInput
v-model=" verificationForm.newPassword"
type="password"
name="password"
placeholder="请输入确认密码"
/>
</ElFormItem>
</template>
<div class="button-div">
<ElButton
size="medium"
type="primary"
class="step-button"
:disabled="disabled"
@click="next"
>
下一步
</ElButton>
<ElButton
size="medium"
class="step-button"
@click="$emit('cancel')"
>
取消
</ElButton>
</div>
</ElForm>
</div>
</template>
<script>
import PuzzleVerification from 'vue-puzzle-verification'
export default {
name: 'ChangePassword',
components: {
PuzzleVerification
},
data() {
const validatePassword = (rule, value, callback) => {
if (value.length < 6) {
callback(new Error('密码不能小于 6 位'))
} else {
callback()
}
}
return {
step: 1,
showPuzzle: false,
verificationForm: {
phoneNum: null,
message: null,
password: null,
newPassword: null
},
verificationRules: {
phoneNum: [{ required: true, trigger: 'blur', message: '请输入账号或手机号' }],
message: [{ required: true, trigger: 'blur', message: '请输入短信验证码' }],
password: [{ required: true, trigger: 'blur', validator: validatePassword }],
newPassword: [{ required: true, trigger: 'blur', validator: validatePassword }]
}
}
},
computed: {
disabled() {
if (this.step === 1) {
return !this.verificationForm.phoneNum
} else if (this.step === 2) {
return !this.verificationForm.message
} else if (this.step === 3) {
return !(this.verificationForm.password && this.verificationForm.newPassword)
} else {
return true
}
}
},
methods: {
handleSuccess() {
console.log('handleSuccess')
this.step = 2
},
next() {
if (this.step === 3) {
console.log('finish')
} else {
if (this.step === 1 && !this.showPuzzle) {
this.showPuzzle = true
return
}
this.step = this.step + 1
}
}
}
}
</script>
<style scoped lang="scss">
$bg: #2d3a4b;
$light_gray: #fff;
$cursor: #fff;
.form-div {
display: flex;
justify-content: center;
width: 100%;
.login-form {
width: 300px;
}
.button-div {
display: flex;
.step-button {
width:50%;
margin-top:10px;
}
}
::v-deep {
.el-input {
margin-top: 15px;
}
}
}
</style>