Commit f48358b7 authored by 杨梦雪's avatar 杨梦雪

验证码

parent 546ff08a
......@@ -178,7 +178,14 @@ export default {
},
};
},
created() {},
created() {
const endTime = window.localStorage.getItem("register_code_time");
const phone = window.localStorage.getItem("register_code_phone");
if (endTime && Number(endTime) > new Date().getTime()) {
this.registerForm.phone = phone;
this.intervalHandle(new Date(), Number(endTime));
}
},
methods: {
// 去注册
toLogin() {
......@@ -188,6 +195,25 @@ export default {
changePwdStatus() {
this.isShowPwd = !this.isShowPwd;
},
// 定时器倒计时
intervalHandle(startTime, endTime) {
// 时间差
const timeLag = intervalTime(startTime, endTime);
console.log(timeLag);
if (!this.timer) {
this.count = timeLag;
this.show = false;
this.timer = setInterval(() => {
if (this.count > 0 && this.count <= timeLag) {
this.count--;
} else {
this.show = true;
clearInterval(this.timer);
this.timer = null;
}
}, 1000);
}
},
// 获取手机验证短信
getCode() {
if (!this.resetForm.phone) {
......@@ -204,44 +230,18 @@ export default {
this.$message.success(res.data.message);
// this.codeTime = parseTime(res.data.data.now);
this.codeTime = res.data.data.now * 1000;
window.localStorage.setItem("codeTime", this.codeTime);
this.time(this.codeTime);
window.localStorage.setItem(
"register_code_time",
res.data.data.now * 1000
);
window.localStorage.setItem(
"register_code_phone",
this.registerForm.phone
);
this.intervalHandle(new Date(), res.data.data.now * 1000);
});
},
time(code) {
let nowdata = new Date().getTime();
// console.log(nowdata);
let codeTime = code;
// console.log(codeTime);
let time = intervalTime(nowdata, codeTime);
console.log(time, "time");
// var min = time.split(":")[1];
// var sec = time.split(":")[2];
// let s = Number(min * 60) + Number(sec);
// console.log(s); //130
// let aa = timeSpan(nowdata, codeTime);
// 倒计时60s
const TIME_COUNT = 60;
if (!this.timer) {
this.count = TIME_COUNT;
this.showCode = false;
this.timer = setInterval(() => {
if (
this.count > 0 &&
this.count <= TIME_COUNT &&
nowdata < codeTime&&
codeTime
) {
this.count--;
} else {
this.showCode = true;
clearInterval(this.timer);
this.timer = null;
}
}, 1000);
}
},
// 表单验证
submitForm() {
this.$refs["resetFormRef"].validate((valid) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment