Skip to content

Commit f8ecfe3

Browse files
authored
feat: 优化重置密码的逻辑,添加验证码校验 (#38)
1 parent 8be40a8 commit f8ecfe3

File tree

2 files changed

+81
-67
lines changed

2 files changed

+81
-67
lines changed

src/api/system/user.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ export function changePwd(data) {
2525
data
2626
})
2727
}
28+
// 输入邮箱获取验证码
29+
export function sendCode(data) {
30+
return request({
31+
url: '/api/base/sendcode',
32+
method: 'post',
33+
data
34+
})
35+
}
2836
// 邮箱更新用户密码(已完成)
2937
export function emailPass(data) {
3038
return request({
@@ -33,7 +41,7 @@ export function emailPass(data) {
3341
data
3442
})
3543
}
36-
// 创建用户(已完成)
44+
// 创建用户(已完成)
3745
export function createUser(data) {
3846
return request({
3947
url: '/api/user/add',

src/views/changePassword/index.vue

+72-66
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,101 @@
11
<template>
2-
<div class="pass-page">
3-
<div class="pass-mian">
4-
<input v-model.trim="mail" placeholder="请输入邮箱" class="pass-input" @change="changeInput($event)">
5-
<div class="pass-btn" @click="submit">确定</div>
6-
</div>
2+
<div class="reset-pass">
3+
<el-form ref="form" :model="form" size="medium" class="form-container">
4+
<el-form-item label="邮箱">
5+
<div class="input-container">
6+
<el-input v-model="form.mail" placeholder="请输入个人邮箱"></el-input>
7+
<el-button type="primary" @click="sendEmailCode">发送验证码</el-button>
8+
</div>
9+
</el-form-item>
10+
<el-form-item label="验证码" class="code-item">
11+
<el-input v-model="form.code" placeholder="请输入验证码"></el-input>
12+
</el-form-item>
13+
<el-form-item class="reset-item">
14+
<el-button type="primary" @click="resetPass">重置密码</el-button>
15+
</el-form-item>
16+
</el-form>
717
</div>
818
</template>
919

1020
<script>
11-
import { emailPass } from '@/api/system/user'
21+
import { emailPass,sendCode } from '@/api/system/user'
22+
import { Message } from 'element-ui'
1223
1324
export default {
1425
name: 'ChangePass',
1526
data() {
1627
return {
1728
// 查询参数
18-
mail: ''
29+
form: {
30+
mail: "",
31+
code: ""
32+
}
1933
}
2034
},
2135
methods: {
22-
// 查询
23-
changeInput(e) {
24-
this.mail = e.target.value
25-
},
26-
async submit() {
27-
try {
28-
const { msg, code } = await emailPass({ mail: this.mail })
29-
if (code === 0) {
36+
// 判断结果
37+
judgeResult(res){
38+
if (res.code==0){
3039
Message({
3140
showClose: true,
32-
message: msg,
41+
message: "操作成功",
3342
type: 'success'
3443
})
35-
// 重新登录
36-
setTimeout(() => {
37-
this.$router.replace({ path: '/login' })
38-
}, 1500)
39-
} else {
40-
Message({
41-
showClose: true,
42-
message: msg,
43-
type: 'error'
44-
})
45-
return false
4644
}
47-
} finally {}
48-
}
45+
},
46+
47+
// 发送邮箱验证码
48+
async sendEmailCode() {
49+
console.log('aaaaaaaa',this.form.mail);
4950
51+
await sendCode({ mail: this.form.mail }).then(res =>{
52+
this.judgeResult(res)
53+
})
54+
},
55+
// 重置密码
56+
async resetPass() {
57+
await emailPass(this.form).then(res =>{
58+
this.judgeResult(res)
59+
})
60+
// 重新登录
61+
setTimeout(() => {
62+
this.$router.replace({ path: '/login' })
63+
}, 1500)
64+
},
5065
}
5166
}
5267
</script>
5368

5469
<style scoped lang="scss">
55-
.pass-page{
56-
.pass-mian{
57-
padding-top:25%;
58-
display: flex;
59-
justify-content: center;
60-
align-items: center;
61-
margin:0 20%;
62-
.pass-input{
63-
flex: 2;
64-
height: 45px;
65-
line-height: 45px;
66-
font-size: 18px;
67-
}
68-
.pass-btn{
69-
margin-left: 20px;
70-
width: 15%;
71-
height: 48px;
72-
background: #1990FF;
73-
color:#fff;
74-
font-size: 18px;
75-
line-height: 48px;
76-
text-align: center;
77-
border-radius: 20px;
78-
}
79-
}
80-
// .container-card{
70+
.reset-pass {
71+
display: flex;
72+
justify-content: center;
73+
align-items: center;
74+
height: 100vh;
75+
}
76+
77+
.form-container {
78+
width: 400px;
79+
}
8180
82-
// padding-top:25%;
83-
// border: 0px solid #fff;
84-
// box-shadow:0 0px 0px;
85-
// border-bottom: 0;
86-
// .demo-form-inline{
87-
// display: flex;
88-
// .from-items{
89-
// text-align: center;
90-
// }
91-
// }
81+
.input-container {
82+
display: flex;
83+
align-items: center;
84+
justify-content: space-between;
85+
}
86+
.input-container .el-input {
87+
flex: 1;
88+
margin-right: 10px;
89+
}
90+
91+
.code-item .el-form-item__label {
92+
width: 80px;
93+
}
94+
.code-item .el-input {
95+
width: 345px;
96+
}
9297
93-
// }
98+
.reset-item {
99+
text-align: right;
94100
}
95101
</style>

0 commit comments

Comments
 (0)