<template>
|
<div class="ResetPassword">
|
<!-- 重置表格 -->
|
<div class="resetForm" v-if="!isReseted">
|
<div class="formHeart">
|
<div class="title">重置密码</div>
|
<el-form
|
:model="formData"
|
:rules="baseInforule"
|
:validate-on-rule-change="false"
|
ref="resetForm"
|
class="demo-rulmargin"
|
>
|
<el-form-item prop="phoneNum">
|
<div class="phoneNum">
|
<el-input
|
placeholder="请输入注册手机号"
|
v-model="formData.phoneNum"
|
class="input-with-select"
|
>
|
</el-input>
|
<div class="iconfont"></div>
|
</div>
|
</el-form-item>
|
|
<el-form-item prop="verifyCode">
|
<el-input
|
v-model="formData.verifyCode"
|
readonly
|
onfocus="this.removeAttribute('readonly');"
|
onblur="this.setAttribute('readonly',true);"
|
autocomplete="off"
|
placeholder="请输入验证码"
|
>
|
</el-input>
|
<el-button
|
class="code-btn"
|
:disabled="codeDisabled"
|
@click="getCode"
|
>{{ codeMsg }}</el-button
|
>
|
<div class="iconfont"></div>
|
</el-form-item>
|
|
<el-form-item prop="password">
|
<el-input
|
show-password
|
v-model="formData.password"
|
placeholder="请设置6-14位登录密码"
|
>
|
</el-input>
|
<div class="iconfont"></div>
|
</el-form-item>
|
|
<el-form-item prop="repassword">
|
<el-input
|
show-password
|
v-model="formData.repassword"
|
placeholder="确认密码"
|
>
|
</el-input>
|
<div class="iconfont"></div>
|
</el-form-item>
|
|
<div>
|
<div
|
class="button submit"
|
:class="{ disabled: btnDisabled }"
|
@click="submit"
|
>
|
提交
|
</div>
|
</div>
|
</el-form>
|
</div>
|
</div>
|
|
<!-- 重置成功 -->
|
<div class="successBox" v-else>
|
<div class="title">
|
<span class="iconfont"></span>
|
重置密码成功
|
</div>
|
<div class="des">请妥善保管您的账户信息</div>
|
<router-link to="/login">
|
<div class="button">重新登录</div>
|
</router-link>
|
</div>
|
</div>
|
</template>
|
|
<script>
|
import { getVerifyCode, forgetPwd } from "@/api/login";
|
import { isPhone, validPassword } from "@/scripts/validate"; // 正则文件
|
|
export default {
|
data() {
|
//密码校验
|
let validatePassword = (rule, value, callback) => {
|
if (value === "") {
|
callback(new Error("请设置密码!"));
|
} else {
|
let result = validPassword(value);
|
if (result) {
|
callback();
|
} else {
|
callback(
|
new Error(
|
"请输入6到14位字符,字母/数字以及标点符号至少包含2种组成的"
|
)
|
);
|
}
|
}
|
};
|
//确认密码校验
|
let validateRePassword = (rule, value, callback) => {
|
if (value === this.formData.password) {
|
callback();
|
} else {
|
callback(new Error("两次输入的密码不一致,请重新输入"));
|
}
|
};
|
return {
|
isReseted: false, //是否重置成功
|
formData: {
|
phoneNum: "",
|
verifyCode: "",
|
password: "",
|
repassword: "",
|
}, //表格数据
|
baseInforule: {
|
password: [{ validator: validatePassword, trigger: "change" }],
|
repassword: [{ validator: validateRePassword, trigger: "change" }],
|
phoneNum: [{ validator: isPhone, trigger: "change" }],
|
verifyCode: [
|
{ required: true, message: "请输入验证码", trigger: "change" },
|
],
|
}, //正则规则
|
codeDisabled: false, //验证码按钮锁定
|
codeMsg: "获取验证码", //验证码按钮文字
|
countdown: 60, //验证码冷却时间
|
};
|
},
|
methods: {
|
//获取按钮显示信息
|
getValidStr() {
|
if (this.countdown > 0 && this.countdown <= 60) {
|
this.countdown--;
|
if (this.countdown !== 0) {
|
this.codeMsg = `${this.countdown}s`;
|
} else {
|
clearInterval(this.timer);
|
this.codeMsg = "获取验证码";
|
this.countdown = 60;
|
this.timer = null;
|
this.codeDisabled = false;
|
}
|
}
|
},
|
//获取验证码
|
getCode() {
|
this.$refs["resetForm"].validateField("phoneNum", (res) => {
|
if (res) {
|
document.querySelector(".phoneNum .el-input__inner").focus();
|
}
|
if (!res) {
|
if (!this.timer) {
|
this.codeDisabled = true;
|
this.getValidStr();
|
this.timer = setInterval(this.getValidStr, 1000);
|
getVerifyCode({ phoneNum: this.formData.phoneNum, type: 1 })
|
.then(() => {
|
this.gotCode = true;
|
})
|
.catch((err) => {
|
if (err.data) {
|
console.log(err);
|
}
|
});
|
}
|
}
|
});
|
},
|
async submit() {
|
const res = await forgetPwd({
|
phoneNum: this.formData.phoneNum,
|
newPwd: this.formData.password,
|
});
|
if (res && res.success) {
|
this.$notify({
|
type: "success",
|
message: "重置成功",
|
});
|
}
|
this.isReseted = true;
|
},
|
},
|
computed: {
|
//控制提交按钮disable
|
btnDisabled() {
|
let disabled = false;
|
for (const key in this.formData) {
|
if (!this.formData[key]) {
|
disabled = true;
|
}
|
}
|
return disabled;
|
},
|
},
|
};
|
</script>
|
|
<style scoped lang="scss" >
|
.resetForm {
|
margin-top: 193px;
|
width: 660px;
|
height: 570px;
|
background-color: #fff;
|
text-align: center;
|
|
.formHeart {
|
overflow: hidden;
|
margin: 0 auto;
|
width: 456px;
|
|
.title {
|
margin-top: 30px;
|
margin-bottom: 50px;
|
font-size: 24px;
|
}
|
|
.el-form-item {
|
margin-bottom: 30px;
|
position: relative;
|
|
::v-deep .el-input__inner {
|
height: 48px;
|
padding: 10px 20px;
|
padding-left: 64px;
|
border-color: #c0c5cc;
|
|
&::-webkit-input-placeholder {
|
font-size: 14px;
|
color: #999;
|
}
|
}
|
|
&.is-error ::v-deep .el-input__inner:focus {
|
border-color: #ff4b33;
|
}
|
|
.code-btn {
|
box-sizing: border-box;
|
width: 101px;
|
height: 30px;
|
position: absolute;
|
top: 9px;
|
right: 20px;
|
padding: 4px 0;
|
padding-left: 20px;
|
border: none;
|
border-left: 1px solid #c0c5cc;
|
border-radius: 0;
|
|
font-size: 16px;
|
line-height: 22px;
|
|
color: #0065ff;
|
|
&:hover {
|
background-color: #fff;
|
}
|
|
&.is-disabled {
|
color: #999999;
|
}
|
}
|
|
.iconfont {
|
position: absolute;
|
top: 4px;
|
left: 20px;
|
font-size: 24px;
|
color: #c0c5cc;
|
}
|
}
|
|
.submit {
|
margin-top: 60px;
|
width: 456px;
|
height: 48px;
|
border-radius: 4px;
|
background: #0065ff;
|
color: #fff;
|
font-size: 16px;
|
font-weight: 700;
|
line-height: 48px;
|
&.disabled {
|
background: rgba(0, 101, 255, 0.5);
|
}
|
}
|
}
|
}
|
|
.successBox {
|
overflow: hidden;
|
margin-top: 253px;
|
height: 450px;
|
width: 660px;
|
background: #ffffff;
|
text-align: center;
|
|
.title {
|
margin-top: 90px;
|
margin-bottom: 40px;
|
font-size: 28px;
|
span {
|
vertical-align: middle;
|
color: rgb(54, 178, 74);
|
margin-right: 20px;
|
font-size: 48px;
|
}
|
}
|
.des {
|
margin-bottom: 102px;
|
font-size: 14px;
|
}
|
|
.button {
|
width: 200px;
|
height: 48px;
|
margin: 0 auto;
|
|
background: #0065ff;
|
color: #fff;
|
border-radius: 4px;
|
font-size: 16px;
|
line-height: 48px;
|
}
|
}
|
</style>
|