025e127e
chenbiao
add 综合平台入口 登录添加验证...
|
1
|
// edit by chenbiao 2022/04/22
|
bf30a091
liuqimichale
init
|
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
|
/**
* 输入框内容检测插件
*/
var $imageCodeValue = $('#login_imgCode_value');
var $imageCode = $('#login_imgCode');
var flagAjax = false;
jQuery.fn.inputCheck = function(properties){
var defaults = {
callback:function(){}
}
jQuery.extend(defaults,properties);
var result = new Object(),realLength = 0, len = this.val().length, charCode = -1;
var regexp = {
china: /[\u4E00-\u9FA5]/, // 中文
decimal: /^\d+(\.\d+)?$/, // 小数
number: /^[0-9]*[1-9][0-9]*$/,
password:/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{6,20}$/,
phone: /^1[3,5,7,8]\d{9}$/, // 手机号码
tel: /^0\d{2,3}-?\d{7,8}$/, // 电话号码
specialPhone: /^(10086|10000|10010)$/, //特殊的电话号码
businessPhone: /^(((400)-(\d{3})-(\d{4}))|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{3,7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)$/, //400的号码验证
email: /\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}/,
peopleId: /\d{17}[\d|x]|\d{15}/,
username: /^[a-zA-Z\u4e00-\u9fa5][a-zA-Z0-9_\u4E00-\u9FA5]{5,15}$/,
date: /^((((19|20)\d{2})-(0?(1|[3-9])|1[012])-(0?[1-9]|[12]\d|30))|(((19|20)\d{2})-(0?[13578]|1[02])-31)|(((19|20)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|((((19|20)([13579][26]|[2468][048]|0[48]))|(2000))-0?2-29))$/,
nbsp: /\s/ //判断空格
}
//计算输入框内容的长度,一个中文等于两个字符
for (var i = 0; i < len; i++) {
charCode = this.val().charCodeAt(i);
if (charCode >= 0 && charCode <= 128) realLength += 1;
else realLength += 2;
}
result.china = regexp.china.test(this.val()) ? true : false;
result.decimal = regexp.decimal.test(this.val()) ? true : false;
result.password = regexp.password.test(this.val()) ? true : false;
result.number = regexp.number.test(this.val()) ? true : false;
result.phone = regexp.phone.test(this.val()) || regexp.tel.test(this.val()) || regexp.specialPhone.test(this.val()) || regexp.businessPhone.test(this.val()) ? true : false;
result.email = regexp.email.test(this.val()) ? true : false;
result.nbsp = regexp.nbsp.test(this.val()) ? true : false;
result.peopleId = regexp.peopleId.test(this.val()) ? true : false;
result.username = regexp.username.test(this.val()) ? true : false;
result.date = regexp.date.test(this.val()) ? true : false;
result.length = realLength/2;
defaults.callback(result);
};
//邮箱验证
function username(obj) {
var _this = obj;
_this.inputCheck({
callback : function(result){
if(!result.email){
_this.next().removeClass('display-hide');
flagAjax = false;
}else{
_this.next().addClass('display-hide');
flagAjax = true;
}
}
});
}
$(document).on("blur",'#userName',function() { //验证邮箱地址
username($(this));
});
//密码验证
function password(obj){
var _this = obj;
_this.inputCheck({
callback : function(result){
if(!result.password){
_this.next().removeClass('display-hide');
flagAjax = false;
}else{
_this.next().addClass('display-hide');
flagAjax = true;
}
}
});
}
$('#password').on("blur", function() { //验证邮箱地址
password($(this));
});
|
025e127e
chenbiao
add 综合平台入口 登录添加验证...
|
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
var fun={
init:function () {
$('#login_code_ifo').text('');
//获取验证码
createCode();
}
};
fun.init();
$(document).on('click','#code',function () {
//获取验证码
createCode();
})
//点击登录
|
bf30a091
liuqimichale
init
|
105
106
107
108
109
|
$('#login-btn').on('click',function () {
var obj1 = $('#userName');
var obj2 = $('#password');
username(obj1);
password(obj2);
|
bf30a091
liuqimichale
init
|
110
|
|
025e127e
chenbiao
add 综合平台入口 登录添加验证...
|
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
// 验证码
var imgCode=document.getElementById("code").value;
var imgCodeId=$('#code').attr('data-id');
var inputCode = document.getElementById("codedate").value.toUpperCase(); //取得输入的验证码并转化为大
//校验 验证码是否匹配正确
if(inputCode.length <= 0) { //若输入的验证码长度为0
//alert("请输入验证码!"); //则弹出请输入验证码
$('#login_error_ifo').text("请输入验证码!");
return;
}
if(inputCode != imgCode ) { //若输入的验证码与产生的验证码不一致时
//alert("验证码输入错误!"); //则弹出验证码输入错误
$('#login_error_ifo').text("验证码输入错误!");
createCode();//刷新验证码
document.getElementById("codedate").value = "";//清空文本框
return;
}
|
bf30a091
liuqimichale
init
|
128
|
|
025e127e
chenbiao
add 综合平台入口 登录添加验证...
|
129
|
$('#login_error_ifo').text('');
|
bf30a091
liuqimichale
init
|
130
|
|
025e127e
chenbiao
add 综合平台入口 登录添加验证...
|
131
132
133
134
135
|
if(flagAjax){
var Username= $('#userName').val();
var Password= $('#password').val();
// var imageCode = $imageCodeValue.val();
// alert("username is "+username+"password is"+password+"code is "+imageCode);
|
bf30a091
liuqimichale
init
|
136
|
|
bf30a091
liuqimichale
init
|
137
|
|
025e127e
chenbiao
add 综合平台入口 登录添加验证...
|
138
139
140
141
|
var opts = {};
opts.method = "POST";
opts.url = dataUrl.util.getLogin();
opts.success = loginSuccess;
|
bf30a091
liuqimichale
init
|
142
|
|
025e127e
chenbiao
add 综合平台入口 登录添加验证...
|
143
144
145
146
147
148
149
150
151
152
153
154
155
|
var data = {
// 'terminalSource':6,
};
data.clientType = sysComm.clientType;
data.sysCode = sysComm.sysCode;
data.grantType = sysComm.grantType;
data.username = Username;
data.password = Password;
data.imgCodeId = imgCodeId;
data.imgCode = imgCode;
data.expiresIn = 60 * 60 * 12;//默认12小时
opts.data = JSON.stringify(data);
sysAjax(opts);
|
bf30a091
liuqimichale
init
|
156
157
158
159
|
}
|
025e127e
chenbiao
add 综合平台入口 登录添加验证...
|
160
|
|
bf30a091
liuqimichale
init
|
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
});
//回车事件
$('#login_imgCode_value').keyup(function(event){
if(event.keyCode ==13){
// $('#login-btn').onClick()
$('#login-btn').trigger("click");
}
});
$('#login_imgCode_value').on('input',function () {
var val = $('#login_imgCode_value').val();
if(val){
$('.verification-logo').addClass('glyphicon glyphicon-remove');
}else{
$('.verification-logo').removeClass('glyphicon glyphicon-remove');
}
});
$('.verification-logo').on('click',function () {
$("#login_imgCode_value").val("");
$('.verification-logo').removeClass('glyphicon glyphicon-remove');
});
|
bf30a091
liuqimichale
init
|
182
|
|
025e127e
chenbiao
add 综合平台入口 登录添加验证...
|
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
|
/**
* 验证码获取 请求接口
* Get getloginimgcode
* @param
*/
var syscode; //在全局定义验证码
function createCode() {
// 发出Ajax请求
$.ajax({
type: "GET",
url: dataUrl.util.imageCodeStr(),
data: null,
dataType: null,
processData: true,
traditional: true,
success: function (res) {
if (res.code === '8888') {
var data = res.data;
var imgCodeId=data.authTokenid;
var imgCode=data.imageCodeStr;
syscode=imgCode;
$('#code').val(imgCode);
$('#code').attr('data-id',imgCodeId);
} else {
console.log(res.msg);
}
},
error: function (err) {
console.log(err);
}
})
};
|
bf30a091
liuqimichale
init
|
220
|
|
bf30a091
liuqimichale
init
|
221
222
223
224
225
226
227
228
229
230
231
232
233
|
//登录成功的函数
function loginSuccess(res) {
if (res.code === '8888') {
// var data = JSON.parse(res.data);
fn.setToken(res.data.accessToken);
fn.setUserName(res.data.userName);
fn.setUserId(res.data.userId);
console.log(res.data.userName);
fn.setOpImgPath(res.data.imgPath);
/**将系统编码及名称放入session.*/
sessionStorage.setItem("sysCode", res.data.sysCode);
sessionStorage.setItem("sysName", res.data.sysName);
|
57746651
Andy
接口请求 菜单
|
234
235
|
//后台返回用户可见的各个项目项目菜单 例如: projectCode:"INTERFACE_PLATFORM" projectName:"接口平台"
sessionStorage.setItem("sysOpProjectDTOList", JSON.stringify(res.data.sysOpProjectDTOList));
|
bf30a091
liuqimichale
init
|
236
237
238
|
//alert("success");
fn.setUserAccount(res.data.userName);
window.location.href = "index.html";
|
025e127e
chenbiao
add 综合平台入口 登录添加验证...
|
239
240
241
242
243
244
|
} else if (res.code == "1012") {
$('#login_error_ifo').text("验证码不匹配");
createCode();//刷新验证码
}else if (res.code == "2000" || res.code === '1004') {
|
bf30a091
liuqimichale
init
|
245
246
247
|
//账号密码不匹配
$('#login_error_ifo').text("账号密码不匹配");
//$error.text("账号或密码错误!");
|
025e127e
chenbiao
add 综合平台入口 登录添加验证...
|
248
|
createCode();
|
bf30a091
liuqimichale
init
|
249
250
251
252
|
} else if (res.code == "2001") {
//账号无有效角色,非有效用户
$('#login_error_ifo').text("账号无效");
//$error.text("账号无有效角色,非有效用户!");
|
025e127e
chenbiao
add 综合平台入口 登录添加验证...
|
253
|
createCode();
|
bf30a091
liuqimichale
init
|
254
255
256
257
258
259
|
} else if (res.code == "2002") {
//验证码错误
// $('.verification-logo').addClass('glyphicon glyphicon-remove');
$('#login_error_ifo').text("验证码错误");
//return false;
// $imageCodeValue.focus();
|
025e127e
chenbiao
add 综合平台入口 登录添加验证...
|
260
|
createCode();
|
bf30a091
liuqimichale
init
|
261
262
|
} else if(res.code == "2010"){
$('#login_error_ifo').text("用户没有关联停车场");
|
025e127e
chenbiao
add 综合平台入口 登录添加验证...
|
263
|
createCode();
|
bf30a091
liuqimichale
init
|
264
265
266
267
268
269
|
}
else {
console.log(res.code);
$('.verification-logo').removeClass('glyphicon glyphicon-remove').addClass('glyphicon glyphicon-ok');
$('#login_error_ifo').text("系统错误");
// $error.text(res.msg);
|
025e127e
chenbiao
add 综合平台入口 登录添加验证...
|
270
|
createCode();
|
bf30a091
liuqimichale
init
|
271
272
273
|
}
}
|