Commit 9c1341c725997956f651ea91c86610352592a118
1 parent
a374798a
登录 login
Showing
2 changed files
with
223 additions
and
2 deletions
js/login.js
1 | /** | 1 | /** |
2 | * Created by chenbiao on 2017/11/20. | 2 | * Created by chenbiao on 2017/11/20. |
3 | */ | 3 | */ |
4 | + | ||
5 | +/** | ||
6 | + * 输入框内容检测插件 | ||
7 | + */ | ||
8 | +var $imageCodeValue = $('#login_imgCode_value'); | ||
9 | +var $imageCode = $('#login_imgCode'); | ||
10 | +var flagAjax = false; | ||
11 | +jQuery.fn.inputCheck = function(properties){ | ||
12 | + var defaults = { | ||
13 | + callback:function(){} | ||
14 | + } | ||
15 | + jQuery.extend(defaults,properties); | ||
16 | + var result = new Object(),realLength = 0, len = this.val().length, charCode = -1; | ||
17 | + var regexp = { | ||
18 | + china: /[\u4E00-\u9FA5]/, // 中文 | ||
19 | + decimal: /^\d+(\.\d+)?$/, // 小数 | ||
20 | + number: /^[0-9]*[1-9][0-9]*$/, | ||
21 | + password:/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{6,20}$/, | ||
22 | + phone: /^1[3,5,7,8]\d{9}$/, // 手机号码 | ||
23 | + tel: /^0\d{2,3}-?\d{7,8}$/, // 电话号码 | ||
24 | + specialPhone: /^(10086|10000|10010)$/, //特殊的电话号码 | ||
25 | + 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的号码验证 | ||
26 | + email: /\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}/, | ||
27 | + | ||
28 | + peopleId: /\d{17}[\d|x]|\d{15}/, | ||
29 | + username: /^[a-zA-Z\u4e00-\u9fa5][a-zA-Z0-9_\u4E00-\u9FA5]{5,15}$/, | ||
30 | + 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))$/, | ||
31 | + nbsp: /\s/ //判断空格 | ||
32 | + } | ||
33 | + | ||
34 | + //计算输入框内容的长度,一个中文等于两个字符 | ||
35 | + for (var i = 0; i < len; i++) { | ||
36 | + charCode = this.val().charCodeAt(i); | ||
37 | + if (charCode >= 0 && charCode <= 128) realLength += 1; | ||
38 | + else realLength += 2; | ||
39 | + } | ||
40 | + | ||
41 | + result.china = regexp.china.test(this.val()) ? true : false; | ||
42 | + result.decimal = regexp.decimal.test(this.val()) ? true : false; | ||
43 | + result.password = regexp.password.test(this.val()) ? true : false; | ||
44 | + result.number = regexp.number.test(this.val()) ? true : false; | ||
45 | + result.phone = regexp.phone.test(this.val()) || regexp.tel.test(this.val()) || regexp.specialPhone.test(this.val()) || regexp.businessPhone.test(this.val()) ? true : false; | ||
46 | + result.email = regexp.email.test(this.val()) ? true : false; | ||
47 | + | ||
48 | + result.nbsp = regexp.nbsp.test(this.val()) ? true : false; | ||
49 | + result.peopleId = regexp.peopleId.test(this.val()) ? true : false; | ||
50 | + result.username = regexp.username.test(this.val()) ? true : false; | ||
51 | + result.date = regexp.date.test(this.val()) ? true : false; | ||
52 | + result.length = realLength/2; | ||
53 | + defaults.callback(result); | ||
54 | +}; | ||
55 | +//邮箱验证 | ||
56 | +function username(obj) { | ||
57 | + var _this = obj; | ||
58 | + _this.inputCheck({ | ||
59 | + callback : function(result){ | ||
60 | + if(!result.email){ | ||
61 | + _this.next().removeClass('display-hide'); | ||
62 | + flagAjax = false; | ||
63 | + }else{ | ||
64 | + _this.next().addClass('display-hide'); | ||
65 | + flagAjax = true; | ||
66 | + } | ||
67 | + } | ||
68 | + }); | ||
69 | +} | ||
70 | +$('#userName').on("blur", function() { //验证邮箱地址 | ||
71 | + username($(this)); | ||
72 | +}); | ||
73 | +//密码验证 | ||
74 | +function password(obj){ | ||
75 | + var _this = obj; | ||
76 | + _this.inputCheck({ | ||
77 | + callback : function(result){ | ||
78 | + if(!result.password){ | ||
79 | + _this.next().removeClass('display-hide'); | ||
80 | + flagAjax = false; | ||
81 | + }else{ | ||
82 | + _this.next().addClass('display-hide'); | ||
83 | + flagAjax = true; | ||
84 | + } | ||
85 | + } | ||
86 | + }); | ||
87 | +} | ||
88 | +$('#password').on("blur", function() { //验证邮箱地址 | ||
89 | + password($(this)); | ||
90 | +}); | ||
91 | +//验证码验证 | ||
92 | +//function verification(obj) { | ||
93 | +// var _this = obj; | ||
94 | +// if(_this.val() !== '1234'){ | ||
95 | +// _this.prev().addClass('glyphicon glyphicon-remove'); | ||
96 | +// return false; | ||
97 | +// }else{ | ||
98 | +// _this.prev().removeClass('glyphicon glyphicon-remove').addClass('glyphicon glyphicon-ok'); | ||
99 | +// } | ||
100 | +//} | ||
101 | +//$('#login_imgCode_value').on("input blur", function() { //验证邮箱地址 | ||
102 | +// verification($(this)); | ||
103 | +//}); | ||
104 | +//点击登陆 | ||
105 | +$('#login-btn').on('click',function () { | ||
106 | + var obj1 = $('#userName'); | ||
107 | + var obj2 = $('#password'); | ||
108 | + username(obj1); | ||
109 | + password(obj2); | ||
110 | + //verification($('#login_imgCode_value')); | ||
111 | + if(flagAjax){ | ||
112 | + var Username= $('#userName').val(); | ||
113 | + var Password= $('#password').val(); | ||
114 | + var imageCode = $imageCodeValue.val(); | ||
115 | + // alert("username is "+username+"password is"+password+"code is "+imageCode); | ||
116 | + | ||
117 | + | ||
118 | + var opts = {}; | ||
119 | + opts.method = "POST"; | ||
120 | + opts.url = dataUrl.util.getLogin(); | ||
121 | + opts.success = loginSuccess; | ||
122 | + | ||
123 | + var data = {}; | ||
124 | + data.clientType = sysComm.clientType; | ||
125 | + data.sysCode = sysComm.sysCode; | ||
126 | + data.grantType = sysComm.grantType; | ||
127 | + data.username = Username; | ||
128 | + data.password = Password; | ||
129 | + data.imgCode = imageCode; | ||
130 | + data.expiresIn = 60 * 60 * 12;//默认12小时 | ||
131 | + opts.data = JSON.stringify(data); | ||
132 | + sysAjax(opts); | ||
133 | + | ||
134 | + } | ||
135 | + | ||
136 | + // window.location.href='index.html'; | ||
137 | +}); | ||
138 | +//回车事件 | ||
139 | +$('#login_imgCode_value').keyup(function(event){ | ||
140 | + if(event.keyCode ==13){ | ||
141 | + // $('#login-btn').onClick() | ||
142 | + $('#login-btn').trigger("click"); | ||
143 | + } | ||
144 | +}); | ||
145 | +$('#login_imgCode_value').on('input',function () { | ||
146 | + var val = $('#login_imgCode_value').val(); | ||
147 | + if(val){ | ||
148 | + $('.verification-logo').addClass('glyphicon glyphicon-remove'); | ||
149 | + }else{ | ||
150 | + $('.verification-logo').removeClass('glyphicon glyphicon-remove'); | ||
151 | + } | ||
152 | + | ||
153 | +}); | ||
154 | +$('.verification-logo').on('click',function () { | ||
155 | + $("#login_imgCode_value").val(""); | ||
156 | + $('.verification-logo').removeClass('glyphicon glyphicon-remove'); | ||
157 | +}); | ||
158 | +getImgCode(); | ||
159 | + | ||
160 | +//点击换验证码 | ||
161 | +$('#login_imgCode').on('click', function () { | ||
162 | + getImgCode(); | ||
163 | +}); | ||
164 | +function getImgCode() { | ||
165 | + var opt = { | ||
166 | + method: "get", | ||
167 | + url: dataUrl.util.getLoginImageCode(), | ||
168 | + success: imgCodeSuccess | ||
169 | + } | ||
170 | + sysAjax(opt); | ||
171 | +} | ||
172 | +function imgCodeSuccess(res) { | ||
173 | + if (res.code === '8888') { | ||
174 | + var imageCodeStr = res.data.imageCodeStr; | ||
175 | + var base64ImgStr = 'data:image/jpeg;base64,' + imageCodeStr; | ||
176 | + fn.setToken(res.data.authTokenid); | ||
177 | + $imageCode.attr('src', base64ImgStr); | ||
178 | + } | ||
179 | + | ||
180 | +} | ||
181 | +//登录成功的函数 | ||
182 | +function loginSuccess(res) { | ||
183 | + if (res.code === '8888') { | ||
184 | + // var data = JSON.parse(res.data); | ||
185 | + fn.setToken(res.data.accessToken); | ||
186 | + fn.setUserName(res.data.userName); | ||
187 | + fn.setUserId(res.data.userId); | ||
188 | + fn.setOpImgPath(res.data.imgPath); | ||
189 | + /**将系统编码及名称放入session.*/ | ||
190 | + sessionStorage.setItem("sysCode", res.data.sysCode); | ||
191 | + sessionStorage.setItem("sysName", res.data.sysName); | ||
192 | + //alert("success"); | ||
193 | + fn.setUserAccount(res.data.userName); | ||
194 | + window.location.href = "index.html"; | ||
195 | + } else if (res.code == "2000" || res.code === '1004') { | ||
196 | + //账号密码不匹配 | ||
197 | + $('#login_error_ifo').text("账号密码不匹配"); | ||
198 | + //$error.text("账号或密码错误!"); | ||
199 | + getImgCode(); | ||
200 | + } else if (res.code == "2001") { | ||
201 | + //账号无有效角色,非有效用户 | ||
202 | + $('#login_error_ifo').text("账号无效"); | ||
203 | + //$error.text("账号无有效角色,非有效用户!"); | ||
204 | + getImgCode(); | ||
205 | + } else if (res.code == "2002") { | ||
206 | + //验证码错误 | ||
207 | + // $('.verification-logo').addClass('glyphicon glyphicon-remove'); | ||
208 | + $('#login_error_ifo').text("验证码错误"); | ||
209 | + //return false; | ||
210 | + // $imageCodeValue.focus(); | ||
211 | + getImgCode(); | ||
212 | + } else if(res.code == "2010"){ | ||
213 | + $('#login_error_ifo').text("用户没有关联停车场"); | ||
214 | + getImgCode(); | ||
215 | + } | ||
216 | + else { | ||
217 | + console.log(res.code); | ||
218 | + $('.verification-logo').removeClass('glyphicon glyphicon-remove').addClass('glyphicon glyphicon-ok'); | ||
219 | + $('#login_error_ifo').text("系统错误"); | ||
220 | + // $error.text(res.msg); | ||
221 | + getImgCode(); | ||
222 | + } | ||
223 | + | ||
224 | +} | ||
4 | \ No newline at end of file | 225 | \ No newline at end of file |
login.html
@@ -34,7 +34,7 @@ | @@ -34,7 +34,7 @@ | ||
34 | <div class="psw-cont"> | 34 | <div class="psw-cont"> |
35 | <div class="cont-psw clearfix"> | 35 | <div class="cont-psw clearfix"> |
36 | <span class="psw-bg"></span> | 36 | <span class="psw-bg"></span> |
37 | - <input class="login-control" type="text" autocomplete="off" placeholder="请输入6-20位字母和数字组成的密码" name="password" id="passWord" maxlength="25"> | 37 | + <input class="login-control" type="text" autocomplete="off" placeholder="请输入6-20位字母和数字组成的密码" name="password" id="password" maxlength="25"> |
38 | </div> | 38 | </div> |
39 | </div> | 39 | </div> |
40 | <!-- yanzhengma --> | 40 | <!-- yanzhengma --> |
@@ -45,7 +45,7 @@ | @@ -45,7 +45,7 @@ | ||
45 | <input class="ver-control verification-input float-left" type="text" autocomplete="off" placeholder="请输入验证码" name="" maxlength="4" id="login_imgCode_value"> | 45 | <input class="ver-control verification-input float-left" type="text" autocomplete="off" placeholder="请输入验证码" name="" maxlength="4" id="login_imgCode_value"> |
46 | </div> | 46 | </div> |
47 | <span class="imgWrap float-left"> | 47 | <span class="imgWrap float-left"> |
48 | - <!--<img src="" id="login_imgCode">--> | 48 | + <img src="" id="login_imgCode"> |
49 | </span> | 49 | </span> |
50 | </div> | 50 | </div> |
51 | <!--error --> | 51 | <!--error --> |