提交 57859252 编写于 作者: laizhilong's avatar laizhilong

注册成功去掉计时器,直接登录

上级 0c134b7e
......@@ -214,8 +214,8 @@
closable: true
});
}
// 3s后自动登录
this.countDown(3);
// 自动登录
this.countDown();
}
}).catch((e: any) => {
const data = e.data;
......@@ -236,58 +236,51 @@
}
/**
* 自动登录倒计时
* 自动登录
*/
public countDown(totalTime: any): void {
public countDown(): void {
// 注册时不允许再点击‘确定注册按钮’
if (!this.canClick) return;
this.canClick = false;
this.confirmRegBtnContent = totalTime + 's后自动登录';
// 设置定时器
let clock = window.setInterval(() => {
// 秒数-1
totalTime--;
this.confirmRegBtnContent = totalTime + 's后自动登录';
if (totalTime < 0) {
// 清除定时器
window.clearInterval(clock);
// 登录请求
const loginname: any = this.form.loginname;
const password: any = this.form.password;
const post: Promise<any> = this.$http.post('v7/login', this.form, true);
post.then((response: any) => {
if (response && response.status === 200) {
const data = response.data;
if (data && data.token) {
localStorage.setItem('token', data.token);
}
if (data && data.user) {
localStorage.setItem('user', JSON.stringify(data.user));
}
// 设置cookie,保存账号密码7天
this.setCookie(loginname, password, 7);
// 跳转首页
const url: any = this.$route.query.redirect ? this.$route.query.redirect : '*';
this.$router.push({path: url});
}
}).catch((error: any) => {
const data = error.data;
if (data && data.detail) {
this.$Message.error({
content: "登录失败," + data.detail,
duration: 3,
closable: true
});
} else {
this.$Message.error({
content: "登录失败",
duration: 3,
closable: true
});
}
this.confirmRegBtnContent = '登录中...';
// 登录请求
const loginname: any = this.form.loginname;
const password: any = this.form.password;
const post: Promise<any> = this.$http.post('v7/login', this.form, true);
post.then((response: any) => {
if (response && response.status === 200) {
const data = response.data;
if (data && data.token) {
localStorage.setItem('token', data.token);
}
if (data && data.user) {
localStorage.setItem('user', JSON.stringify(data.user));
}
// 设置cookie,保存账号密码7天
this.setCookie(loginname, password, 7);
// 跳转首页
const url: any = this.$route.query.redirect ? this.$route.query.redirect : '*';
this.$router.push({path: url});
}
}).catch((error: any) => {
const data = error.data;
if (data && data.detail) {
this.$Message.error({
content: "登录失败," + data.detail,
duration: 3,
closable: true
});
} else {
this.$Message.error({
content: "登录失败",
duration: 3,
closable: true
});
}
}, 1000)
this.canClick = true;
this.confirmRegBtnContent = '确定注册';
});
}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册