Authored by 周少峰

Merge branch 'feature/11130'

@@ -26,15 +26,15 @@ @@ -26,15 +26,15 @@
26 </div> 26 </div>
27 </li> 27 </li>
28 28
29 - <li class="relative">  
30 - <input id="account" class="account input va" name="account" value="{{bindMobile}}" type="text" 29 + <li class="relative password-login">
  30 + <input id="account1" class="account input va" name="account" value="{{bindMobile}}" type="text"
31 placeholder="邮箱/手机号码" autocomplete="off"> 31 placeholder="邮箱/手机号码" autocomplete="off">
32 <span class="err-tip hide"> 32 <span class="err-tip hide">
33 <i></i> 33 <i></i>
34 <em></em> 34 <em></em>
35 </span> 35 </span>
36 </li> 36 </li>
37 - <li class="relative password-login login"> 37 + <li class="relative password-login">
38 <input id="password" class="password input va" name="password" type="password" placeholder="密码" 38 <input id="password" class="password input va" name="password" type="password" placeholder="密码"
39 autocomplete="off" maxlength="20"> 39 autocomplete="off" maxlength="20">
40 <span id="caps-lock" class="caps-lock hide">大写状态开启</span> 40 <span id="caps-lock" class="caps-lock hide">大写状态开启</span>
@@ -44,7 +44,17 @@ @@ -44,7 +44,17 @@
44 </span> 44 </span>
45 </li> 45 </li>
46 46
47 - <li class="relative clearfix sms-login login hide"> 47 +
  48 + <li class="relative clearfix sms-login hide">
  49 + <input id="account2" class="account input va" name="account2" value="{{bindMobile}}" type="text"
  50 + placeholder="手机号码" autocomplete="off">
  51 + <span class="err-tip hide">
  52 + <i></i>
  53 + <em></em>
  54 + </span>
  55 + </li>
  56 +
  57 + <li class="relative clearfix sms-login hide">
48 <input id="captcha-sms" class="input va captcha-sms-input" type="text" name="captcha" 58 <input id="captcha-sms" class="input va captcha-sms-input" type="text" name="captcha"
49 placeholder="短信验证码" 59 placeholder="短信验证码"
50 autocomplete="off" maxlength="4"> 60 autocomplete="off" maxlength="4">
@@ -53,8 +53,7 @@ module.exports = { @@ -53,8 +53,7 @@ module.exports = {
53 name: 'error', 53 name: 'error',
54 level: 'error', 54 level: 'error',
55 filename: 'logs/error.log', 55 filename: 'logs/error.log',
56 - handleExceptions: true,  
57 - maxFiles: 7 56 + handleExceptions: true
58 }, 57 },
59 udp: { // send by udp 58 udp: { // send by udp
60 measurement: 'yohobuy_node_log', 59 measurement: 'yohobuy_node_log',

8.64 KB | W: | H:

10 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin
1 /** 1 /**
2 * 登录 2 * 登录
3 - * @author: xuqi<qi.xu@yoho.cn>  
4 - * @date: 2015/12/11  
5 - *  
6 * @author: tao.huang<tao.huang@yoho.cn> 3 * @author: tao.huang<tao.huang@yoho.cn>
7 * @date: 2016/8/29 4 * @date: 2016/8/29
8 */ 5 */
@@ -36,10 +33,16 @@ var $ = require('yoho-jquery'); @@ -36,10 +33,16 @@ var $ = require('yoho-jquery');
36 /* 初始化变量 */ 33 /* 初始化变量 */
37 /**************************************************************************/ 34 /**************************************************************************/
38 35
39 -// 帐号  
40 -var $accountInput = $('#account'),  
41 - getAccountVal = function() {  
42 - return $.trim($accountInput.val()); 36 +// 密码输入帐号
  37 +var $accountInput1 = $('#account1'),
  38 + getAccountVal1 = function() {
  39 + return $.trim($accountInput1.val());
  40 + },
  41 +
  42 +// 短信输入帐号
  43 + $accountInput2 = $('#account2'),
  44 + getAccountVal2 = function() {
  45 + return $.trim($accountInput2.val());
43 }, 46 },
44 47
45 // 密码 48 // 密码
@@ -82,7 +85,8 @@ var $accountInput = $('#account'), @@ -82,7 +85,8 @@ var $accountInput = $('#account'),
82 }; 85 };
83 86
84 // 提示 87 // 提示
85 -var $accountTip = $accountInput.siblings('.err-tip'), 88 +var $accountTip1 = $accountInput1.siblings('.err-tip'),
  89 + $accountTip2 = $accountInput2.siblings('.err-tip'),
86 $passwordTip = $passwordInput.siblings('.err-tip'), 90 $passwordTip = $passwordInput.siblings('.err-tip'),
87 $captchaImgTip = $captchaImgInput.siblings('.err-tip'), 91 $captchaImgTip = $captchaImgInput.siblings('.err-tip'),
88 $captchaSmsTip = $captchaSmsInput.siblings('.err-tip'), 92 $captchaSmsTip = $captchaSmsInput.siblings('.err-tip'),
@@ -120,17 +124,17 @@ var LoginType = { @@ -120,17 +124,17 @@ var LoginType = {
120 url: '/passport/login/password/checkuser', 124 url: '/passport/login/password/checkuser',
121 type: 'POST', 125 type: 'POST',
122 data: { 126 data: {
123 - phoneNum: getAccountVal(), 127 + phoneNum: getAccountVal1(),
124 area: getAreaCodeVal() 128 area: getAreaCodeVal()
125 } 129 }
126 }).then(function(result) { 130 }).then(function(result) {
127 var defer = $.Deferred(); // eslint-disable-line 131 var defer = $.Deferred(); // eslint-disable-line
128 132
129 if (result.code === 200) { 133 if (result.code === 200) {
130 - hideAccountTip(); // eslint-disable-line 134 + hideAccountTip1(); // eslint-disable-line
131 defer.resolve(); 135 defer.resolve();
132 } else { 136 } else {
133 - showAccountTip(result.message); // eslint-disable-line 137 + showAccountTip1(result.message); // eslint-disable-line
134 defer.reject(); 138 defer.reject();
135 } 139 }
136 140
@@ -143,7 +147,11 @@ var LoginType = { @@ -143,7 +147,11 @@ var LoginType = {
143 return 'password'; 147 return 'password';
144 }, 148 },
145 name: 'PasswordLogin', 149 name: 'PasswordLogin',
146 - validate: prePasswordLoginWithValidate // eslint-disable-line 150 + validate: prePasswordLoginWithValidate, // eslint-disable-line
  151 + hideEle: '.sms-login',
  152 + getAccountVal: getAccountVal1, // eslint-disable-line
  153 + showAccountTip: showAccountTip1, // eslint-disable-line
  154 + hideAccountTip: hideAccountTip1 // eslint-disable-line
147 }, 155 },
148 SMSLogin: { 156 SMSLogin: {
149 ele: '.sms-login', 157 ele: '.sms-login',
@@ -152,17 +160,17 @@ var LoginType = { @@ -152,17 +160,17 @@ var LoginType = {
152 url: '/passport/login/sms/checkuser', 160 url: '/passport/login/sms/checkuser',
153 type: 'POST', 161 type: 'POST',
154 data: { 162 data: {
155 - mobile: getAccountVal(), 163 + mobile: getAccountVal2(),
156 area: getAreaCodeVal() 164 area: getAreaCodeVal()
157 } 165 }
158 }).then(function(result) { 166 }).then(function(result) {
159 var defer = $.Deferred(); // eslint-disable-line 167 var defer = $.Deferred(); // eslint-disable-line
160 168
161 if (result.code === 200) { 169 if (result.code === 200) {
162 - hideAccountTip(); // eslint-disable-line 170 + hideAccountTip2(); // eslint-disable-line
163 defer.resolve(); 171 defer.resolve();
164 } else { 172 } else {
165 - showAccountTip(result.message); // eslint-disable-line 173 + showAccountTip2(result.message); // eslint-disable-line
166 defer.reject(); 174 defer.reject();
167 } 175 }
168 176
@@ -175,7 +183,11 @@ var LoginType = { @@ -175,7 +183,11 @@ var LoginType = {
175 return 'sms'; 183 return 'sms';
176 }, 184 },
177 name: 'SMSLogin', 185 name: 'SMSLogin',
178 - validate: preSmsLoginWithValidate // eslint-disable-line 186 + validate: preSmsLoginWithValidate, // eslint-disable-line
  187 + hideEle: '.password-login',
  188 + getAccountVal: getAccountVal2, // eslint-disable-line
  189 + showAccountTip: showAccountTip2, // eslint-disable-line
  190 + hideAccountTip: hideAccountTip2 // eslint-disable-line
179 } 191 }
180 }; 192 };
181 193
@@ -186,7 +198,8 @@ changeLoginTypeEvent.add(function(type) { @@ -186,7 +198,8 @@ changeLoginTypeEvent.add(function(type) {
186 198
187 // 重置状态 199 // 重置状态
188 changeLoginTypeEvent.add(function() { 200 changeLoginTypeEvent.add(function() {
189 - hideAccountTip(); // eslint-disable-line 201 + hideAccountTip1(); // eslint-disable-line
  202 + hideAccountTip2(); // eslint-disable-line
190 hideCaptchaImgTip(); // eslint-disable-line 203 hideCaptchaImgTip(); // eslint-disable-line
191 hideCaptchaSmsTip(); // eslint-disable-line 204 hideCaptchaSmsTip(); // eslint-disable-line
192 hidePasswordTip(); // eslint-disable-line 205 hidePasswordTip(); // eslint-disable-line
@@ -197,12 +210,11 @@ changeLoginTypeEvent.add(function() { @@ -197,12 +210,11 @@ changeLoginTypeEvent.add(function() {
197 $captchaSmsTokenHideInput.val(''); 210 $captchaSmsTokenHideInput.val('');
198 }); 211 });
199 212
200 -// placeholder 变化  
201 changeLoginTypeEvent.add(function(type) { 213 changeLoginTypeEvent.add(function(type) {
202 if (type === LoginType.SMSLogin.name) { 214 if (type === LoginType.SMSLogin.name) {
203 - $accountInput.attr('placeholder', '手机号码'); 215 + $accountInput2.val($accountInput1.val());
204 } else { 216 } else {
205 - $accountInput.attr('placeholder', '邮箱/手机号码'); 217 + $accountInput1.val($accountInput2.val());
206 } 218 }
207 }); 219 });
208 220
@@ -230,12 +242,20 @@ function errTipHide($tip, $input) { @@ -230,12 +242,20 @@ function errTipHide($tip, $input) {
230 242
231 /**************************************************************************/ 243 /**************************************************************************/
232 // 帐号 244 // 帐号
233 -function showAccountTip(msg) {  
234 - return errTipShow($accountTip, $accountInput, msg); 245 +function showAccountTip1(msg) {
  246 + return errTipShow($accountTip1, $accountInput1, msg);
235 } 247 }
236 248
237 -function hideAccountTip() {  
238 - return errTipHide($accountTip, $accountInput); 249 +function hideAccountTip1() {
  250 + return errTipHide($accountTip1, $accountInput1);
  251 +}
  252 +
  253 +function showAccountTip2(msg) {
  254 + return errTipShow($accountTip2, $accountInput2, msg);
  255 +}
  256 +
  257 +function hideAccountTip2() {
  258 + return errTipHide($accountTip2, $accountInput2);
239 } 259 }
240 260
241 /**************************************************************************/ 261 /**************************************************************************/
@@ -274,7 +294,7 @@ function hideCaptchaSmsTip() { @@ -274,7 +294,7 @@ function hideCaptchaSmsTip() {
274 294
275 // 本地验证用户输入格式 295 // 本地验证用户输入格式
276 function validateAccountPasswordLocal() { 296 function validateAccountPasswordLocal() {
277 - var account = getAccountVal(), 297 + var account = currentLogin.getAccountVal(),
278 err; 298 err;
279 299
280 var defer = $.Deferred(); // eslint-disable-line 300 var defer = $.Deferred(); // eslint-disable-line
@@ -295,16 +315,16 @@ function validateAccountPasswordLocal() { @@ -295,16 +315,16 @@ function validateAccountPasswordLocal() {
295 } 315 }
296 316
297 if (defer.state() === 'resolved') { 317 if (defer.state() === 'resolved') {
298 - hideAccountTip(); 318 + currentLogin.hideAccountTip();
299 } else { 319 } else {
300 - showAccountTip(err); 320 + currentLogin.showAccountTip(err);
301 } 321 }
302 return defer.promise(); 322 return defer.promise();
303 } 323 }
304 324
305 -// 本地验证 325 +// 短信验证用户输入格式
306 function validateAccountSmsLocal() { 326 function validateAccountSmsLocal() {
307 - var account = getAccountVal(), 327 + var account = currentLogin.getAccountVal(),
308 err; 328 err;
309 329
310 var defer = $.Deferred(); // eslint-disable-line 330 var defer = $.Deferred(); // eslint-disable-line
@@ -321,9 +341,9 @@ function validateAccountSmsLocal() { @@ -321,9 +341,9 @@ function validateAccountSmsLocal() {
321 } 341 }
322 342
323 if (defer.state() === 'resolved') { 343 if (defer.state() === 'resolved') {
324 - hideAccountTip(); 344 + currentLogin.hideAccountTip();
325 } else { 345 } else {
326 - showAccountTip(err); 346 + currentLogin.showAccountTip(err);
327 } 347 }
328 return defer.promise(); 348 return defer.promise();
329 } 349 }
@@ -333,7 +353,7 @@ function validateAccountSmsLocal() { @@ -333,7 +353,7 @@ function validateAccountSmsLocal() {
333 function validateAccount() { 353 function validateAccount() {
334 return currentLogin.validateAccountLocal() 354 return currentLogin.validateAccountLocal()
335 .then(currentLogin.validateAccountAsync) 355 .then(currentLogin.validateAccountAsync)
336 - .then(hideAccountTip); 356 + .then(currentLogin.hideAccountTip);
337 } 357 }
338 358
339 359
@@ -484,7 +504,7 @@ function validateCaptchaSmsAsync() { @@ -484,7 +504,7 @@ function validateCaptchaSmsAsync() {
484 type: 'POST', 504 type: 'POST',
485 data: { 505 data: {
486 area: getAreaCodeVal(), 506 area: getAreaCodeVal(),
487 - mobile: getAccountVal(), 507 + mobile: currentLogin.getAccountVal(),
488 code: getCaptchaSmsVal() 508 code: getCaptchaSmsVal()
489 } 509 }
490 }).then(function(result) { 510 }).then(function(result) {
@@ -537,13 +557,13 @@ function validateWithSmsMode() { @@ -537,13 +557,13 @@ function validateWithSmsMode() {
537 // password登录之前验证 557 // password登录之前验证
538 function prePasswordLoginWithValidate() { 558 function prePasswordLoginWithValidate() {
539 return (function() { 559 return (function() {
540 - var account = getAccountVal(), 560 + var account = currentLogin.getAccountVal(),
541 password = getPasswordVal(); 561 password = getPasswordVal();
542 562
543 var defer = $.Deferred(); // eslint-disable-line 563 var defer = $.Deferred(); // eslint-disable-line
544 564
545 if (account === '') { 565 if (account === '') {
546 - showAccountTip('请输入账户名'); 566 + showAccountTip1('请输入账户名');
547 defer.reject(); 567 defer.reject();
548 } 568 }
549 569
@@ -554,7 +574,7 @@ function prePasswordLoginWithValidate() { @@ -554,7 +574,7 @@ function prePasswordLoginWithValidate() {
554 574
555 if (account === '' && password === '') { 575 if (account === '' && password === '') {
556 // 账户名和密码都为空的情况下点击登陆,只在账户输入框后显示错误提示 576 // 账户名和密码都为空的情况下点击登陆,只在账户输入框后显示错误提示
557 - showAccountTip('请输入账户名和密码'); 577 + showAccountTip1('请输入账户名和密码');
558 578
559 $passwordTip.addClass('hide'); 579 $passwordTip.addClass('hide');
560 $passwordInput.addClass('error'); 580 $passwordInput.addClass('error');
@@ -568,13 +588,13 @@ function prePasswordLoginWithValidate() { @@ -568,13 +588,13 @@ function prePasswordLoginWithValidate() {
568 // sms登录之前验证 588 // sms登录之前验证
569 function preSmsLoginWithValidate() { 589 function preSmsLoginWithValidate() {
570 return (function() { 590 return (function() {
571 - var account = getAccountVal(), 591 + var account = currentLogin.getAccountVal(),
572 password = getCaptchaSmsVal(); 592 password = getCaptchaSmsVal();
573 593
574 var defer = $.Deferred(); // eslint-disable-line 594 var defer = $.Deferred(); // eslint-disable-line
575 595
576 if (account === '') { 596 if (account === '') {
577 - showAccountTip('请输入手机号'); 597 + showAccountTip1('请输入手机号');
578 defer.reject(); 598 defer.reject();
579 } 599 }
580 600
@@ -585,7 +605,7 @@ function preSmsLoginWithValidate() { @@ -585,7 +605,7 @@ function preSmsLoginWithValidate() {
585 605
586 if (password === '' && account === '') { 606 if (password === '' && account === '') {
587 // 账户名和密码都为空的情况下点击登陆,只在账户输入框后显示错误提示 607 // 账户名和密码都为空的情况下点击登陆,只在账户输入框后显示错误提示
588 - showAccountTip('请输入手机号和短信验证码'); 608 + showAccountTip1('请输入手机号和短信验证码');
589 609
590 $captchaSmsTip.addClass('hide'); 610 $captchaSmsTip.addClass('hide');
591 $captchaSmsInput.addClass('error'); 611 $captchaSmsInput.addClass('error');
@@ -626,7 +646,7 @@ function sendCaptchaSmsAsync() { @@ -626,7 +646,7 @@ function sendCaptchaSmsAsync() {
626 url: '/passport/login/sms/send', 646 url: '/passport/login/sms/send',
627 data: { 647 data: {
628 area: getAreaCodeVal(), 648 area: getAreaCodeVal(),
629 - mobile: getAccountVal() 649 + mobile: currentLogin.getAccountVal()
630 } 650 }
631 }); 651 });
632 } 652 }
@@ -637,7 +657,7 @@ function checkUserAuthCountAsync() { @@ -637,7 +657,7 @@ function checkUserAuthCountAsync() {
637 url: '/passport/login/account', 657 url: '/passport/login/account',
638 type: 'GET', 658 type: 'GET',
639 data: { 659 data: {
640 - account: getAccountVal() 660 + account: currentLogin.getAccountVal()
641 } 661 }
642 }).then(function(res) { 662 }).then(function(res) {
643 if (res.data && res.data.needCaptcha) { 663 if (res.data && res.data.needCaptcha) {
@@ -658,7 +678,7 @@ function login() { @@ -658,7 +678,7 @@ function login() {
658 type: 'POST', 678 type: 'POST',
659 data: { 679 data: {
660 areaCode: getAreaCodeVal(), 680 areaCode: getAreaCodeVal(),
661 - account: getAccountVal(), 681 + account: currentLogin.getAccountVal(),
662 password: currentLogin.creditableToken(), 682 password: currentLogin.creditableToken(),
663 captcha: getCaptchaImgVal(), 683 captcha: getCaptchaImgVal(),
664 isRemember: getRememberMeVal(), 684 isRemember: getRememberMeVal(),
@@ -730,7 +750,14 @@ $(document).on('click', function(e) { @@ -730,7 +750,14 @@ $(document).on('click', function(e) {
730 /**************************************************************************/ 750 /**************************************************************************/
731 751
732 // 邮箱自动完成后失去焦点:1. 本地验证格式;2.服务器检查用户是否注册;3.检查验证用户次数 752 // 邮箱自动完成后失去焦点:1. 本地验证格式;2.服务器检查用户是否注册;3.检查验证用户次数
733 -mailAc($accountInput, function() { 753 +mailAc($accountInput1, function() {
  754 + return currentLogin.validateAccountLocal().then(function() {
  755 + return currentLogin.validateAccountAsync().always(checkUserAuthCountAsync);
  756 + });
  757 +});
  758 +
  759 +// 短信下手机输入框失去焦点:
  760 +$accountInput2.on('blur', function() {
734 return currentLogin.validateAccountLocal().then(function() { 761 return currentLogin.validateAccountLocal().then(function() {
735 return currentLogin.validateAccountAsync().always(checkUserAuthCountAsync); 762 return currentLogin.validateAccountAsync().always(checkUserAuthCountAsync);
736 }); 763 });
@@ -819,7 +846,8 @@ $switchLoginType.on('click', 'div', function() { @@ -819,7 +846,8 @@ $switchLoginType.on('click', 'div', function() {
819 $this.addClass('selected'); 846 $this.addClass('selected');
820 $this.siblings().removeClass('selected'); 847 $this.siblings().removeClass('selected');
821 848
822 - $(LoginType[type].ele).removeClass('hide').siblings('.login').addClass('hide'); 849 + $(LoginType[type].ele).removeClass('hide');
  850 + $(LoginType[type].hideEle).addClass('hide');
823 }); 851 });
824 852
825 /**************************************************************************/ 853 /**************************************************************************/
@@ -844,7 +872,7 @@ $('input.va').on('keypress', function(e) { @@ -844,7 +872,7 @@ $('input.va').on('keypress', function(e) {
844 changeLoginTypeEvent.fire('PasswordLogin'); 872 changeLoginTypeEvent.fire('PasswordLogin');
845 873
846 // 只带账户名的页面,密码输入获得焦点 874 // 只带账户名的页面,密码输入获得焦点
847 -if (($accountInput.val() !== '' || $accountInput.val() === $accountInput.attr('placeholder')) && 875 +if (($accountInput1.val() !== '' || $accountInput1.val() === $accountInput1.attr('placeholder')) &&
848 $passwordInput.val() === '') { 876 $passwordInput.val() === '') {
849 $passwordInput.focus(); 877 $passwordInput.focus();
850 } 878 }