login.js
17.4 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
/**
* 页面描述:登陆页面
*
*/
import {
mapGetters,
mapActions,
mapState
} from "vuex";
import api from '@/api/api'
import {
httpGet,
httpPost
} from '@/api/fetch-api.js'
import modalComp from '@/components/modal-comp/modal-comp.vue';
import modalSimpleComp from '@/components/modal-simple-comp/modal-simple-comp.vue';
import modalProtocolComp from '@/components/modal-protocol-comp/modal-protocol-comp.vue';
import modalUploadCardComp from '@/components/modal-upload-card-comp/modal-upload-card-comp.vue';
import {
passwordEncrypt
} from '@/utils/encrypt.js';
import { contactMethodCheck, checkVerifyCode } from '@utils/utils.js';
import Vue from 'vue';
import { Loading } from 'vant';
Vue.use(Loading);
export default {
data() {
return {
loading: false,
key: 'value',
type: 1, // 1:帐密登陆 2:OTP登陆 3:OTP注册密码,
values: {
// 返回的token,串连整个流程,后台安全校验使用
token: "",
deviceId: "",
vcodeuuid: "",
token: "",
deviceId: "",
imageBase64: "",
password: "",
passwordRepeat: ""
},
times: {
interval: 0, // 索引
remain: 0, // 剩余时间
tip: "" // 显示的文字
},
loginForm: {
userId: "",
password: "",
// userId: "18334783910",
// password: "qweqwe123",
// userId: "91239123",
// password: "ccc123!@#",
// userId: "18145729463",
// password: "ccc123!@#",
// userId: "15927024254",
// password: "a1234567@",
imageValue: "",
mobileNo: "",
otp: ""
},
loginCheck: {
showImageCode: false,
agreeProtocol: false
},
errorTips: {
// 账密登录页
e1: "", // 账号
e2: "", // 密码
e3: "", // 图像验证码
e4: "", // 勾选同意
// 短信验证码
oe1: "", // 账号
oe2: "", // 短信验证码
oe3: "", // 图像验证码
// 注册
p4: "",
p5: ""
},
mobileTip: {},
mobileOptions: [],
mobileNoType: "hk",// 选择的手机好类型
modalVisiable: false,
modalSimpleVisiable: false,
modalUploadCardVisiable: false,
modalProtocolVisiable: false,
targetPath: "",
modalIcon: "succ",
modalContent: ""
}
},
components: {
modalComp,
modalSimpleComp,
modalProtocolComp,
modalUploadCardComp
},
computed: {
...mapState({
userInfo: state => state.userInfo
}),
locale() {
return this.$i18n.locale || 'tc';
},
i18n() {
return this.$i18n.messages && this.$i18n.locale ? this.$i18n.messages[this.$i18n.locale] : {};
},
pwdLoginDisabled() {
let b1 = !this.loginCheck.agreeProtocol;
let b2 = !this.loginForm.userId;
let b3 = !this.loginForm.password;
let b = b1 || b2 || b3;
return b;
},
pwdLoginDisabledOneAccountCenterOff() {
let b1 = !this.loginCheck.agreeProtocol;
let b2 = !this.loginForm.userId;
// let b3 = !this.loginForm.password;
let b3 = false;
let b4 = !this.loginForm.otp;
let b = b1 || b2 || b3 || b4;
if (!b) {
let mobile = this.loginForm.userId;
let m1 = contactMethodCheck('hkmobile', mobile);
let m2 = contactMethodCheck('mobile', mobile);
b = b || !(m1 || m2);
}
return b;
},
otpLoginDisabled() {
let b1 = !this.loginCheck.agreeProtocol;
let b2 = !this.loginForm.mobileNo;
let b3 = !checkVerifyCode(this.loginForm.otp);
let b4 = !this.values.token;
let b5 = this.values.vcodeuuid && !this.loginForm.imageValue;
return b1 || b2 || b3 || b4 || b5;
},
submitDisabled() {
let b1 = !this.values.password || this.checkPassword(this.values.password) ? true : false;
let b2 = this.values.passwordRepeat != this.values.password ? true : false;
return b1 || b2;
},
oneAccountCenterOff() {
return window.global.oneAccountCenterOff;
}
},
methods: {
showModal(content, icon) {
icon = !icon || typeof icon === "undefined" ? "succ" : icon;
this.modalIcon = icon;
this.modalContent = content;
if (icon == "succ") {
this.modalVisiable = true;
} else {
this.modalSimpleVisiable = true;
}
},
closeModal() {
this.modalVisiable = false;
this.modalSimpleVisiable = false;
this.modalProtocolVisiable = false;
},
onCheckHandler() { },
onProtocolHandler() {
this.modalProtocolVisiable = true;
},
onSubmitHandler() { },
toRegisterPage() {
this.$router.push({
path: "/register"
});
},
onForgetHandler() {
this.$router.push({
path: "/password/find"
});
},
onLoginTypeHandler(val) {
this.type = val;
},
initData() {
if (this.userInfo && (this.userInfo.sid || this.userInfo.name)) {
this.$router.push({
path: "/"
});
}
let mobileOptions = JSON.parse(JSON.stringify(this.i18n.register.mobileOptions));
this.mobileOptions = mobileOptions;
this.mobileTip = this.mobileOptions[0];
},
// 获取并判断是否显示图形验证码
handlerIsShowImageVcode() {
return new Promise((resolve, reject) => {
httpPost({
url: api.stdIsShowImageVcode,
data: {
deviceId: this.values.deviceId,
userId: this.loginForm.userId
}
}).then(response => {
// 判断是否显示图形验证码
if (this._handlerIsShowImageVcodeResponse(response)) {
resolve(response);
}
})
});
},
_handlerIsShowImageVcodeResponse(response) {
if (response.returnCode == "0") {
this.values.token = response.data.token;
if (response.data.isShowVcode == "N") {
return true;
} else {
// image 值:
this.loginCheck.showImageCode = true;
this.values.vcodeuuid = response.data.vcodeuuid;
this.values.imageBase64 = response.data.image;
}
}
return false;
},
handlerRefreshVcode() {
// 刷新图形二维码
},
handlerLogin() {
if ((this.type == 1 && this.pwdLoginDisabled) || (this.type == 2 && this.otpLoginDisabled)) {
return;
}
this.refreshDeviceId();
if (!this.loginCheck.agreeProtocol) {
this._showAgreeProtocalTips();
return;
}
if (this.type == 1) {
this._passwordLogin();
} else {
this._otpLogin();
}
},
userIdLegalCheck() {
let mobile = this.loginForm.userId;
let m1 = contactMethodCheck('hkmobile', mobile);
let m2 = contactMethodCheck('mobile', mobile);
// console.log("userIdLegalCheck:", m1, m2)
if (!m1 && !m2) {
this._showMobileNoIllegalTip()
return false;
}
return true;
},
// 不接入一账通登陆
pwdLoginWhenOneAccountCenterOff() {
if (this.pwdLoginDisabledOneAccountCenterOff) {
return;
}
if (this.loading) {
return;
}
this.loading = true;
let data = {
account: this.loginForm.userId,
// password: this.loginForm.password,
otp: this.loginForm.otp
};
httpPost({
url: api.doLoginV2,
data: data
}).then(res => {
this.loading = false;
this.$store.commit("SET_USER_INFO", res);
this._redirectTo();
}).catch(e => {
this.loading = false;
switch (e.code) {
case 404:
// this.errorTips.e2 = this.i18n.login.tips.e5;
this.errorTips.e1 = this.i18n.login.tips.e8;
break;
case 1104:
this.errorTips.oe2 = this.i18n.login.tips.oe4;
break;
case 1102:
this.errorTips.e2 = this.i18n.login.tips.e6;
break;
case 1101:
this.errorTips.e2 = this.i18n.login.tips.e7;
break;
}
})
},
sendOTPWhenOneAccountCenterOff() {
// 发送短信验证码
let m1 = contactMethodCheck('hkmobile', this.loginForm.userId);
let m2 = contactMethodCheck('mobile', this.loginForm.userId);
if (!m1 && !m2) {
this._showMobileNoIllegalTip();
return;
}
if (this.times.remain > 0) {
return;
}
let data = {
mobile: this.loginForm.userId,
lan : this.locale
}
this._startTimeClick();
httpPost({
url: api.refreshSmgOtp,
data: data
}).then(res => {
}).catch(e => {
console.error(e);
})
},
// 刷新图形二维码
_passwordLogin() {
if (!this.loginForm.userId) {
this._showEmptyInputTips();
return;
}
if (!this.loginForm.password) {
this._showEmptyPasswordTips();
return;
}
if (this.loading) {
return;
}
this.loading = true;
this.handlerIsShowImageVcode().then(() => {
httpPost({
url: api.gsLogin,
data: {
deviceId: this.values.deviceId,
loginName: this.loginForm.userId,
loginPwd: passwordEncrypt(this.loginForm.password)
}
}).then(response => {
this.loading = false;
this._handlerLoginResponse(response);
}).catch(err => {
this.loading = false;
});
});
},
// 处理登录结果
_handlerLoginResponse(response) {
// let res = response.content;
if (response.returnCode == 0 || response.returnCode == "0") {
this.$store.commit("SET_USER_INFO", response.data);
this._redirectTo();
} else {
this._showLoginErrorMessage(response);
}
},
_showEmptyInputTips() {
let message = this.i18n.login.tips.e1;
this.errorTips.e1 = message;
},
_showEmptyPasswordTips() {
let message = this.i18n.login.tips.e2;
this.errorTips.e2 = message;
},
_showAgreeProtocalTips() {
let message = this.i18n.login.tips.e4;
// this.showModal(message, "info");
},
_showLoginErrorMessage(response) {
// response.returnCode = "GS_RESETPWD_ERROR_NOUSERINFO";
switch (response.returnCode) {
case "SMS_ERROR_006":
// 短信验证码不正确
// this.showModal(this.i18n.login.tips.oe4, "info");
this.errorTips.oe2 = this.i18n.login.tips.oe4;
break;
case "BIZ_ERROR_018":
// 账号或密码不正确
this.errorTips.e2 = this.i18n.login.tips.e5;
// this.showModal(this.i18n.login.tips.e5, "info");
break;
case "BIZ_ERROR_011":
case "BIZ_ERROR_012":
case "OTP_ERROR_015":
// 登录错误4次、5次
this.errorTips.e2 = response.returnMsg;
// this.showModal(response.returnMsg, "info");
return;
case "GS_RESETPWD_ERROR_NOUSERINFO":
// 这个是用户OTP验证成功后没有账号导致
this.type = 3;
break;
case "COMMON_ERROR_009":
this.errorTips.p5 = response.returnMsg;
break;
default:
if (this.type == 3) {
this.errorTips.p5 = response.returnMsg;
} else {
this.errorTips.e2 = this.i18n.login.tips.e5;
this.errorTips.oe2 = this.i18n.login.tips.e5;
}
// this.showModal(this.i18n.login.tips.e5, "info");
break;
}
},
_redirectTo() {
let path = this.$route.query.callback || "/";
this.$router.push({
path: path
});
},
// opt登陆
_otpLogin() {
this._checkOptParams().then(() => {
let data = {
mobileNo: this.loginForm.mobileNo,
token: this.values.token,
otp: this.loginForm.otp,
deviceId: this.refreshDeviceId()
};
if (this.loading) {
return;
}
this.loading = true;
httpPost({
url: api.otpLogin,
data: data
}).then(response => {
this.loading = false;
this._handlerLoginResponse(response);
}).catch(err => {
this.loading = false;
});
});
},
_checkOptParams() {
return new Promise((resolve, reject) => {
this._checkMobileLegal().then(() => {
if (!checkVerifyCode(this.loginForm.otp)) {
this._showOtpEmptyTips();
return;
}
if (!this.values.token) {
this._showGetOptTips();
return;
}
resolve();
});
})
},
_showGetOptTips() {
let message = this.i18n.login.tips.oe1;
this.errorTips.oe2 = message;
// alert('请先获取短信验证码');
},
_showImageValueTip() {
let message = this.i18n.login.tips.oe2;
this.errorTips.oe3 = message;
// alert("请输入图片验证码")
},
_showOtpEmptyTips() {
let message = this.i18n.login.tips.oe3;
this.errorTips.oe2 = message;
// alert('请输入短信验证码');
},
handlerStdSendOTP() {
// 发送短信验证码
this._checkMobileLegal().then(() => {
if (this.times.remain > 0) {
return;
}
if (this.values.vcodeuuid && !this.loginForm.imageValue) {
this._showImageValueTip();
return;
}
this._handlerIsShowImageVcode().then(() => {
this._startStdSendOTP();
});
});
},
// 刷新
handlerRefreshImageValue() {
httpPost({
url: api.stdRefreshVcode,
data: {
vcodeuuid: this.values.vcodeuuid
}
}).then(response => {
this.values.imageBase64 = response.data.image;
})
},
checkPassword(password) {
if (password.length < 8) {
return this.i18n.register.tips.e7;
}
// 匹配字母
let m1 = /([a-z])+/.test(password);
let m2 = /([A-Z])+/.test(password);
// 匹配数字
let m3 = /([0-9])+/.test(password);
// 匹配特殊字符
let m4 = /[^a-zA-Z0-9]+/.test(password);
if ((m1 | m2) & m3 & m4) {
return "";
} else {
return this.i18n.register.tips.e8;
}
},
_checkMobileLegal() {
// 检测手机号是否正确
return new Promise((resolve, reject) => {
let mobile = this.loginForm.mobileNo;
if (this.mobileNoType == "hk") {
if (!contactMethodCheck('hkmobile', mobile)) {
this._showMobileNoIllegalTip()
return;
}
} else {
if (!contactMethodCheck('mobile', mobile)) {
this._showMobileNoIllegalTip()
return;
}
}
resolve(true);
});
},
_handlerIsShowImageVcode() {
return new Promise((resolve, reject) => {
// 如果这个值不为空,标识出现了图片验证码,不需要重新询问是否需要图像验证码了
// if (this.values.vcodeuuid) {
// resolve();
// return;
// }
httpPost({
url: api.stdIsShowImageVcode,
data: {
deviceId: this.values.deviceId,
userId: this.loginForm.mobileNo
}
}).then(response => {
// 判断是否显示图形验证码
if (this._handlerIsShowImageVcodeResponse(response)) {
resolve(response);
}
})
});
},
_showMobileNoIllegalTip() {
let message = this.i18n.login.tips.oe0;
this.errorTips.oe1 = message;
if (this.oneAccountCenterOff)
this.errorTips.e1 = message;
// alert("手机号不正确");
},
_startStdSendOTP() {
// 正式发送OTP信号
let data = {
mobileNo: this.loginForm.mobileNo,
token: this.values.token,
signFactor: new Date().getTime(),
scene: "otpLogin",
deviceId: this.refreshDeviceId()
}
if (this.values.vcodeuuid) {
data["vcodeuuid"] = this.values.vcodeuuid;
data["imageValue"] = this.loginForm.imageValue;
}
httpPost({
url: api.stdSendOTP,
data: data
}).then(response => {
switch (response.returnCode) {
case "0":
this._startTimeClick();
this.errorTips.oe2 = "";
break;
default:
this.errorTips.oe2 = response.returnMsg;
break;
};
});
},
_startTimeClick() {
this.times.remain = 120;
let _this = this;
let i18n = this.$i18n.messages[this.$i18n.locale] || {};
let msg = i18n.register.coutTips;
_this.times.tip = msg.replace("{second}", _this.times.remain);
this.times.interval = setInterval(function () {
if (_this.times.remain <= 0) {
clearInterval(_this.times.interval);
_this.times.interval = 0;
_this.times.remain = 0;
return;
}
_this.times.remain--;
_this.times.tip = msg.replace("{second}", _this.times.remain);
_this.$set(_this, 'times', _this.times);
}, 1000);
},
refreshDeviceId() {
if (!this.values.deviceId) {
this.values.deviceId = (Math.random() + "").substring(2)
}
return this.values.deviceId
},
onRegisterHandler() {
let c = this.checkPassword(this.values.password);
if (c) {
this.errorTips.p4 = c;
} else {
this.errorTips.p4 = "";
let data = {
deviceId: this.values.deviceId,
token: this.values.token,
mobileNo: this.loginForm.mobileNo,
loginPwd: passwordEncrypt(this.values.password)
};
this.loading = true;
httpPost({
url: api.otpRegisterAndLogin,
data: data
}).then(response => {
this.loading = false;
this._handlerLoginResponse(response);
}).catch(e => {
this.loading = false;
})
}
},
modalCallback() {
this.modalVisiable = false;
this.modalSimpleVisiable = false;
this.modalUploadCardVisiable = false;
if (this.targetPath) {
this.$router.push({
"path": this.targetPath
});
}
},
closeCallback() {
this.modalVisiable = false;
this.modalSimpleVisiable = false;
this.modalUploadCardVisiable = false;
}
},
watch: {
mobileNoType() {
this.mobileOptions.forEach(element => {
if (element.type == this.mobileNoType) {
this.$set(this, 'mobileTip', element);
console.log(this.mobileTip);
}
})
this.errorTips.oe1 = "";
this.errorTips.oe2 = "";
this.errorTips.oe3 = "";
},
type() {
this.loginCheck.showImageCode = false;
},
'loginForm.userId': function () {
this.errorTips.e1 = "";
},
'loginForm.password': function () {
this.errorTips.e2 = "";
},
'loginForm.mobileNo': function () {
this.errorTips.oe1 = "";
},
'loginForm.otp': function () {
this.errorTips.oe2 = "";
},
'loginForm.imageValue': function () {
this.errorTips.oe3 = "";
},
'values.password': function () {
this.$set(this.errorTips, 'p4', this.checkPassword(this.values.password));
},
'values.passwordRepeat': function () {
if (this.values.password != this.values.passwordRepeat) {
let message = this.i18n.register.tips.e9;
this.errorTips.p5 = message;
} else {
this.errorTips.p5 = "";
}
},
},
mounted() {
this.initData();
// console.log("PK === ", this.PK)
// console.log("E === ", this.E)
},
created() {
try {
this.$root.eventBus.$off("login");
} catch (e) {
}
this.$root.eventBus.$on("login", () => {
this.type = 1;
});
}
}