Login.js
2.18 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
let href = window.location.href + '';
let $ = require('jquery');
let $captcha = $('#captcha');
if(href) {
let index = href.indexOf('?code');
if(index > 0) {
let code = +href.substring(index + '?code='.length);
// 登陆错误
if(code === 400) {
alert("用户名或者密码错误,请确认!");
}
if(code === 405) {
alert('图形验证失败');
}
window.location.href = "/login";
}
}
var captcha = {
init: function() {
var that = this;
$.ajax({
type: 'GET',
dataType: 'json',
url: 'login/captcha',
success: function (result) {
if (result.code === 500) {
alert('验证码加载异常');
window.location.reload(true);
return;
}
initGeetest && initGeetest({ // eslint-disable-line
gt: result.data.gt,
challenge: result.data.challenge,
width: '100%',
product: 'float', // 产品形式,包括:float,embed,popup。注意只对PC版验证码有效
new_captcha: result.data.new_captcha,
offline: !result.data.success // 表示用户后台检测极验服务器是否宕机,一般不需要关注
}, that.initCallback);
},
error: function (rs) {
console.log(rs)
}
});
},
initCallback: function(captchaObj) {
captchaObj.onSuccess(function() {
var validate = captchaObj.getValidate();
var result = [
validate.geetest_challenge,
validate.geetest_validate,
validate.geetest_seccode
];
$captcha.val(result.join(','));
$('#loginForm').submit();
});
captchaObj.onError(function() {
$captcha.val('');
});
captchaObj.onClose(function() {
$captcha.val('');
});
captchaObj.appendTo(document.getElementById('img-check-main'));
}
}
$(function() {
captcha.init();
});