login.js
3.39 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
const util = new window.publicMethod() ;
new Vue({
el: '#app',
data: {
loginForm: {
employeeId: '',
phoneNumber: '',
verifyCode: ''
},
countdown: 0,
countdownTimer: null,
clickFlag: false
},
methods: {
getVerifyCode() {
let pa = this.loginForm
if (!pa.employeeId) {
util.toast('请输入工号');
return;
}
if (!pa.phoneNumber) {
util.toast('请输入手机号');
return;
}
if (!/^1[3-9]\d{9}$/.test(pa.phoneNumber)) {
util.toast('请输入正确的手机号');
return;
}
if(this.clickFlag){
return
}
this.clickFlag = true
util.httpRequest({
url: '/mobile/sendSms',
middleUrl: '/zhijian-trial/api',
data: {
campaignId: pa.employeeId,
phone: pa.phoneNumber,
},
}).then(res=>{
if(res.code == 200){
util.toast('验证码已发送,请注意查收')
// 开始倒计时
let __this = this
this.countdown = 60;
this.countdownTimer = setInterval(() => {
this.countdown--;
if (this.countdown <= 0) {
clearInterval(this.countdownTimer);
__this.clickFlag = false
}
}, 1000);
}else{
this.clickFlag = false
util.toast(res.msg || '获取失败')
}
}).catch(()=>{
this.clickFlag = false
})
},
login() {
let pa = this.loginForm
// 验证表单
if (!pa.employeeId) {
util.toast('请输入工号');
return;
}
if (!pa.phoneNumber) {
util.toast('请输入手机号');
return;
}
// 验证手机号格式
if (!/^1[3-9]\d{9}$/.test(pa.phoneNumber)) {
util.toast('请输入正确的手机号');
return;
}
if (!pa.verifyCode) {
util.toast('请输入验证码');
return;
}
// 验证验证码格式(假设6位数字)
if (!/^\d{6}$/.test(pa.verifyCode)) {
util.toast('请输入6位验证码');
return;
}
util.httpRequest({
url: '/mobile/login',
middleUrl: '/zhijian-trial/api',
data: {
campaignId: pa.employeeId,
phone: pa.phoneNumber,
smsCode: pa.verifyCode
},
}).then(res=>{
if(res.code == 200){
}else{
util.toast(res.msg || '登录失败')
}
})
}
},
created(){
},
beforeDestroy() {
// 清除定时器
if (this.countdownTimer) {
clearInterval(this.countdownTimer);
}
}
});