FindPwd.vue
6.8 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<template>
<div class="login_pwd">
<!-- 找回密码 -->
<el-dialog
:visible="pwdVisible"
@update:visible="$emit('update:pwdVisible',false)"
width="636px"
:before-close="handleClose"
:close-on-click-modal="false"
center
>
<el-form
:model="ruleForm"
:rules="rules"
ref="ruleForm"
label-width="100px"
class="demo-ruleForm"
>
<el-form-item label="手机号" prop="name">
<el-input v-model="ruleForm.name" maxlength="11" placeholder="请输入手机号"></el-input>
</el-form-item>
<el-form-item label="验证码" prop="code" class="ver_code">
<el-input v-model="ruleForm.code" maxlength="4" placeholder="请输入验证码"></el-input>
<!-- 获取验证码 -->
<div class="code_btn" v-show="isShow" @click="getCode">获取验证码</div>
<div class="code_btn sended" v-show="!isShow">{{auth_time}}秒后重发</div>
</el-form-item>
<el-form-item label="新密码" prop="newPwd">
<el-input type="password" minlength="6" v-model="ruleForm.newPwd" placeholder="请输入新密码"></el-input>
</el-form-item>
<el-form-item label="确认密码" prop="oldPwd">
<el-input type="password" v-model="ruleForm.oldPwd" placeholder="确认密码"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="submitForm('ruleForm')">找回密码</el-button>
</el-form-item>
<!-- 联系管理员 -->
<div class="contact">
<p @click="contact">联系管理员</p>
</div>
</el-form>
<!-- 联系管理员 -->
<ContactAdmin :contactVisible.sync="contactVisible" v-if="contactVisible"></ContactAdmin>
</el-dialog>
</div>
</template>
<script>
// 联系管理员
import ContactAdmin from "./ContactAdmin";
import { get, post } from "@/api/http";
import { Notification } from "element-ui";
export default {
props: ["pwdVisible", "pwdType"],
data() {
// 电话号码验证
var phoneReg = /^[1][3,4,5,7,8][0-9]{9}$/;
var validatePhone = (rule, value, callback) => {
if (!value) {
return callback(new Error("请输入11位手机号码"));
}
setTimeout(() => {
if (!phoneReg.test(value)) {
callback(new Error("号码不存在,请输入正确的手机号"));
} else {
callback();
}
}, 100);
};
// 验证码
// 密码验证
var regex = new RegExp("");
var validatePwd = (rule, value, callback) => {
if (!value) {
return callback(new Error("密码不能为空,请输入密码"));
}
setTimeout(() => {
console.log(value)
if (!/((?=.*[a-z])(?=.*\d)|(?=[a-z])(?=.*[#@!~%^&*])|(?=.*\d)(?=.*[#@!~%^&*]))[a-z\d#@!~%^&*]{6,16}/i.test(value)) {
callback(new Error("密码不能为纯数字、纯字符或纯字母"));
} else {
callback();
}
}, 100);
};
return {
isShow: true,
sending: false,
auth_time: 0,
contactVisible: false,
ruleForm: {
name: "",
code: "",
newPwd: "",
oldPwd: ""
},
rules: {
name: [
{
required: true,
validator: validatePhone,
trigger: "blur"
}
],
code: [
{ required: true, message: "验证码为空,请重新验证码", trigger: "blur" }
],
newPwd: [
{
required: true,
validator:validatePwd,
trigger: "blur"
}
],
oldPwd: [
{
required: true,
message: "密码不能为空,请输入密码",
trigger: "blur"
}
]
},
groupId: "",
schoolId:""
};
},
methods: {
handleClose: function() {
this.$emit("update:pwdVisible", false);
},
// 获取验证码
getCode() {
// 找回密码
let tel = /^1(3|4|5|6|7|8|9)\d{9}$/;
let that = this;
if (!tel.test(that.ruleForm.name)) {
Notification.info({
title: "提示",
message: "请输入手机号",
duration: 1500
});
return "";
}
let url = "/api/sms/send";
let params = {
mobile: this.ruleForm.name,
event: "resetpwd",
type: this.pwdType
};
let auth_timetimer;
get(url, params).then(res => {
that.isShow = !that.isShow;
that.auth_time = 60;
auth_timetimer = setInterval(function() {
that.auth_time--;
if (that.auth_time <= 0) {
that.isShow = true;
clearInterval(auth_timetimer);
}
}, 1000);
// that.sending = true;
});
if (!this.sending) {
}
},
// 找回密码
submitForm(formName) {
this.$refs[formName].validate(valid => {
if (valid) {
if (this.ruleForm.newPwd == this.ruleForm.oldPwd) {
let url = "/api/common/resetpwd";
let params = {
mobile: this.ruleForm.name,
captcha: this.ruleForm.code,
newpassword: this.ruleForm.newPwd,
confirmpassword: this.ruleForm.oldPwd,
type: this.pwdType,
schoolId:this.schoolId
};
get(url, params).then(res => {
this.$emit("update:pwdVisible", false);
Notification.info({
title: "提示",
message: "找回密码成功",
duration: 1500
});
});
} else {
Notification.info({
title: "提示",
message: "密码不一致,请重新输入",
duration: 1500
});
}
}
});
},
// 联系管理员
contact: function() {
this.contactVisible = true;
}
},
components: {
ContactAdmin
},
mounted() {
this.schoolId = this.$route.params.test;
console.log(this.schoolId,111)
},
watch:{
'$route'(to,from){
console.log(to,from)
this.schoolId = this.$route.params.test;
localStorage.setItem("schoolSymbol",this.schoolId)
}
},
};
</script>
<style scoped>
/* 获取验证码按钮 */
.ver_code {
position: relative;
}
.code_btn {
position: absolute;
top: 7px;
right: 25px;
width: 110px;
height: 36px;
background: #409eff;
border-radius: 18px;
font-size: 18px;
font-family: Source Han Sans SC;
font-weight: 400;
line-height: 36px;
text-align: center;
color: rgba(255, 255, 255, 1);
opacity: 1;
}
.sended{
background: #f3f3f3;
color: #8C9198;
}
.contact {
color: #bdc4ce;
font-size: 14px;
text-align: right;
margin-right: 24px;
margin-top: -17px;
line-height: 1;
}
</style>