login.js
4.28 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
const util = new window.publicMethod() ;
new Vue({
el: '#app',
data: {
platform: 'yx',
loginForm: {
employeeId: '',
phoneNumber: '',
verifyCode: '123456'
},
countdown: 0,
countdownTimer: null,
clickFlag: false
},
methods: {
tabChang(type){
this.platform = type
localStorage.setItem('platform',type)
if(type == 'gw'){
this.loginForm.employeeId = '54321'
this.loginForm.phoneNumber = '15611154004'
}else if(type == 'yx'){
this.loginForm.employeeId = '12345'
this.loginForm.phoneNumber = '13718590607'
}else{
this.loginForm.employeeId = '54321'
this.loginForm.phoneNumber = '13212789513'
}
},
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: '/send-sms',
data: {
personnelCode: 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.message || '获取失败')
}
}).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: '/phone-login',
data: {
personnelCode: pa.employeeId,
phone: pa.phoneNumber,
smsCode: pa.verifyCode
},
}).then(res=>{
if(res.code == 200){
localStorage.setItem('userInfo',JSON.stringify(res.data.personnel))
localStorage.setItem('tokenInfo',JSON.stringify(res.data.tokenInfo))
if(this.platform == 'gw'){
window.location.href = 'addBusi.html'
}else{
window.location.href = 'myBusi.html'
}
}else{
util.toast(res.message || '登录失败')
}
})
}
},
created(){
localStorage.setItem('platform',this.platform)
},
beforeDestroy() {
// 清除定时器
if (this.countdownTimer) {
clearInterval(this.countdownTimer);
}
}
});