Authored by lore-w

完善信息页面逻辑 code review by liuyue

@@ -78,10 +78,21 @@ @@ -78,10 +78,21 @@
78 {{!-- 注册页--}} 78 {{!-- 注册页--}}
79 {{#if registerPage}} 79 {{#if registerPage}}
80 <script> 80 <script>
81 - seajs.use('js/passport/reg'); 81 + seajs.use('js/passport/reg', function (reg) {
  82 + reg.init('reg');
  83 + });
82 </script> 84 </script>
83 {{/if}} 85 {{/if}}
84 86
  87 +{{!-- 第三方登录完善信息页--}}
  88 +{{#if thirdPage}}
  89 +<script>
  90 + seajs.use('js/passport/reg', function (reg) {
  91 + reg.init('third');
  92 + });
  93 +</script>
  94 +{{/if}}
  95 +
85 {{!-- 找回密码--}} 96 {{!-- 找回密码--}}
86 {{#if backPage}} 97 {{#if backPage}}
87 <script> 98 <script>
@@ -83,14 +83,30 @@ validateResult = [ @@ -83,14 +83,30 @@ validateResult = [
83 ]; 83 ];
84 84
85 //手机号ajax校验 85 //手机号ajax校验
86 -function phoneAjaxFn(callback) {  
87 - $.ajax({  
88 - url: '/passport/register/checkmobile',  
89 - type: 'POST',  
90 - data: { 86 +function phoneAjaxFn(page, callback) {
  87 + var url,
  88 + data;
  89 +
  90 + if (page === 'reg') {
  91 + url = '/passport/register/checkmobile';
  92 + data = {
91 mobile: $pn.val(), 93 mobile: $pn.val(),
92 area: $region.text().split('+')[1] 94 area: $region.text().split('+')[1]
  95 + };
  96 + } else if (page === 'third') {
  97 + url = '/passport/autouserinfo/bindCheck';
  98 + data = {
  99 + mobile: $pn.val(),
  100 + area: $region.text().split('+')[1],
  101 + openId: 1,
  102 + sourceType: 'QQ'
  103 + };
93 } 104 }
  105 +
  106 + $.ajax({
  107 + url: url,
  108 + type: 'POST',
  109 + data: data
94 }).then(function(data) { 110 }).then(function(data) {
95 switch (data.code) { 111 switch (data.code) {
96 case 200: 112 case 200:
@@ -108,10 +124,17 @@ function phoneAjaxFn(callback) { @@ -108,10 +124,17 @@ function phoneAjaxFn(callback) {
108 } 124 }
109 125
110 //图形验证码ajax校验 126 //图形验证码ajax校验
111 -function picCaptchaAjaxFn(callback) { 127 +function picCaptchaAjaxFn(page, callback) {
  128 + var url;
  129 +
  130 + if (page === 'reg') {
  131 + url = '/passport/register/piccaptcha';
  132 + } else if (page === 'third') {
  133 + url = '/passport/autouserinfo/checkPicCode';
  134 + }
112 $.ajax({ 135 $.ajax({
113 type: 'POST', 136 type: 'POST',
114 - url: '/passport/register/piccaptcha', 137 + url: url,
115 data: { 138 data: {
116 code: $ca.val(), 139 code: $ca.val(),
117 mobile: $pn.val(), 140 mobile: $pn.val(),
@@ -123,7 +146,7 @@ function picCaptchaAjaxFn(callback) { @@ -123,7 +146,7 @@ function picCaptchaAjaxFn(callback) {
123 validateResult[1].message = ''; 146 validateResult[1].message = '';
124 validateResult[1].status = true; 147 validateResult[1].status = true;
125 break; 148 break;
126 - case 404: 149 + case 400:
127 validateResult[1].message = '图形验证码错误'; 150 validateResult[1].message = '图形验证码错误';
128 validateResult[1].status = false; 151 validateResult[1].status = false;
129 break; 152 break;
@@ -133,10 +156,17 @@ function picCaptchaAjaxFn(callback) { @@ -133,10 +156,17 @@ function picCaptchaAjaxFn(callback) {
133 } 156 }
134 157
135 //短信验证码ajax校验 158 //短信验证码ajax校验
136 -function msgCaptchaAjaxFn(callback) { 159 +function msgCaptchaAjaxFn(page, callback) {
  160 + var url;
  161 +
  162 + if (page === 'reg') {
  163 + url = '/passport/register/msgcaptcha';
  164 + } else if (page === 'third') {
  165 + url = '/passport/autouserinfo/checkBindMsg';
  166 + }
137 $.ajax({ 167 $.ajax({
138 type: 'POST', 168 type: 'POST',
139 - url: '/passport/register/msgcaptcha', 169 + url: url,
140 data: { 170 data: {
141 code: $ca.val(), 171 code: $ca.val(),
142 mobile: $pn.val(), 172 mobile: $pn.val(),
@@ -148,7 +178,7 @@ function msgCaptchaAjaxFn(callback) { @@ -148,7 +178,7 @@ function msgCaptchaAjaxFn(callback) {
148 validateResult[2].message = ''; 178 validateResult[2].message = '';
149 validateResult[2].status = true; 179 validateResult[2].status = true;
150 break; 180 break;
151 - case 404: 181 + case 400:
152 validateResult[2].message = '短信验证码错误'; 182 validateResult[2].message = '短信验证码错误';
153 validateResult[2].status = false; 183 validateResult[2].status = false;
154 break; 184 break;
@@ -159,7 +189,7 @@ function msgCaptchaAjaxFn(callback) { @@ -159,7 +189,7 @@ function msgCaptchaAjaxFn(callback) {
159 } 189 }
160 190
161 // 验证 191 // 验证
162 -function validateRule($element, callback) { 192 +function validateRule(page, $element, callback) {
163 193
164 var val = $.trim($element.val()), 194 var val = $.trim($element.val()),
165 regionCode; 195 regionCode;
@@ -181,7 +211,7 @@ function validateRule($element, callback) { @@ -181,7 +211,7 @@ function validateRule($element, callback) {
181 callback(); 211 callback();
182 212
183 } else { 213 } else {
184 - phoneAjaxFn(callback); 214 + phoneAjaxFn(page, callback);
185 } 215 }
186 216
187 //图形验证码校验 217 //图形验证码校验
@@ -200,7 +230,7 @@ function validateRule($element, callback) { @@ -200,7 +230,7 @@ function validateRule($element, callback) {
200 230
201 // 并且手机号正确 231 // 并且手机号正确
202 if (validateResult[0].status) { 232 if (validateResult[0].status) {
203 - picCaptchaAjaxFn(callback); 233 + picCaptchaAjaxFn(page, callback);
204 } else { 234 } else {
205 validateResult[1].message = '图形验证码错误'; 235 validateResult[1].message = '图形验证码错误';
206 validateResult[1].status = false; 236 validateResult[1].status = false;
@@ -226,7 +256,7 @@ function validateRule($element, callback) { @@ -226,7 +256,7 @@ function validateRule($element, callback) {
226 256
227 // 并且图形验证码正确 257 // 并且图形验证码正确
228 if (validateResult[1].status) { 258 if (validateResult[1].status) {
229 - msgCaptchaAjaxFn(callback); 259 + msgCaptchaAjaxFn(page, callback);
230 } else { 260 } else {
231 validateResult[2].message = '短信验证码错误'; 261 validateResult[2].message = '短信验证码错误';
232 validateResult[2].status = false; 262 validateResult[2].status = false;
@@ -379,14 +409,16 @@ function pwdFn($obj) { @@ -379,14 +409,16 @@ function pwdFn($obj) {
379 409
380 // 失去焦点时开始校验 410 // 失去焦点时开始校验
381 // Tips: 不可以在获得焦点的时候验证,获得焦点和失去焦点的间隔太小,如果中间存在ajax校验的话会出现问题 411 // Tips: 不可以在获得焦点的时候验证,获得焦点和失去焦点的间隔太小,如果中间存在ajax校验的话会出现问题
382 -$registerPage.find('.va').keyup(function() { 412 +// ( ▼-▼ )注册页和信息完善页面接口不同
  413 +exports.init = function(page) {
  414 + $registerPage.find('.va').keyup(function() {
383 415
384 var j, 416 var j,
385 statusLen = 0, 417 statusLen = 0,
386 vLen = validateResult.length, 418 vLen = validateResult.length,
387 $that = $(this); 419 $that = $(this);
388 420
389 - validateRule($(this), function() { 421 + validateRule(page, $(this), function() {
390 showErrTip(); // 显示错误提示 422 showErrTip(); // 显示错误提示
391 showBorder(); // 显示红色边框 423 showBorder(); // 显示红色边框
392 424
@@ -422,32 +454,48 @@ $registerPage.find('.va').keyup(function() { @@ -422,32 +454,48 @@ $registerPage.find('.va').keyup(function() {
422 pwdFn($that); 454 pwdFn($that);
423 } 455 }
424 456
425 -}).blur(function() { 457 + }).blur(function() {
426 458
427 /*validateRule($(this), function() { 459 /*validateRule($(this), function() {
428 showErrTip(); 460 showErrTip();
429 showBorder(); // 显示红色边框 461 showBorder(); // 显示红色边框
430 });*/ 462 });*/
431 -}); 463 + });
432 464
433 -$regionSelect.change(function() { 465 + $regionSelect.change(function() {
434 466
435 $region.text('+' + $('#region').val()); 467 $region.text('+' + $('#region').val());
436 468
437 - validateRule($pn, showErrTip); //验证  
438 -}); 469 + validateRule(page, $pn, showErrTip); //验证
  470 + });
439 471
440 -// 点击发送验证码  
441 -$sendCaptcha.click(function() {  
442 - var timeResidue = 10,  
443 - t; 472 + // 点击发送验证码
  473 + $sendCaptcha.click(function() {
  474 + var timeResidue = 20,
  475 + t,
  476 + url;
444 477
445 if ($(this).hasClass('disable')) { 478 if ($(this).hasClass('disable')) {
446 return; 479 return;
447 } 480 }
448 481
449 - //todo ajax 482 + if (page === 'reg') {
  483 + url = '/passport/register/sendBindMsg';
  484 + } else if (page === 'third') {
  485 + url = '/passport/autouserinfo/sendBindMsg';
  486 + }
450 487
  488 + //todo ajax 发送验证码
  489 + $.ajax({
  490 + type: 'POST',
  491 + url: url,
  492 + data: {
  493 + area: $region.text().split('+')[1],
  494 + mobile: $pn.val(),
  495 + code: $ca.val()
  496 + }
  497 + }).then(function(data) {
  498 + if (data.code === 200) {
451 t = setInterval(function() { 499 t = setInterval(function() {
452 if (timeResidue <= 0) { 500 if (timeResidue <= 0) {
453 $sendCaptcha.removeClass('disable').val('获取短信验证码'); 501 $sendCaptcha.removeClass('disable').val('获取短信验证码');
@@ -456,10 +504,20 @@ $sendCaptcha.click(function() { @@ -456,10 +504,20 @@ $sendCaptcha.click(function() {
456 } 504 }
457 $sendCaptcha.addClass('disable').val(timeResidue-- + '秒可重新发送'); 505 $sendCaptcha.addClass('disable').val(timeResidue-- + '秒可重新发送');
458 }, 1000); 506 }, 1000);
459 -}); 507 + }
  508 + });
  509 + });
  510 +
  511 + //ajax表单提交
  512 + $registerBtn.click(function() {
460 513
461 -//form表单提交  
462 -$registerBtn.click(function() { 514 + var url;
  515 +
  516 + if (page === 'reg') {
  517 + url = '/passport/register/mobileregister';
  518 + } else if (page === 'third') {
  519 + url = '/passport/autouserinfo/bindMobile';
  520 + }
463 521
464 if ($(this).hasClass('disable')) { 522 if ($(this).hasClass('disable')) {
465 return; 523 return;
@@ -468,7 +526,7 @@ $registerBtn.click(function() { @@ -468,7 +526,7 @@ $registerBtn.click(function() {
468 //ajax提交 526 //ajax提交
469 $.ajax({ 527 $.ajax({
470 type: 'POST', 528 type: 'POST',
471 - url: '/passport/register/mobileregister', 529 + url: url,
472 data: { 530 data: {
473 area: $region.text().split('+')[1], 531 area: $region.text().split('+')[1],
474 mobile: $pn.val(), 532 mobile: $pn.val(),
@@ -507,12 +565,13 @@ $registerBtn.click(function() { @@ -507,12 +565,13 @@ $registerBtn.click(function() {
507 565
508 }); 566 });
509 } 567 }
510 -}); 568 + });
511 569
512 -$('.change-captcha').click(function() { 570 + $('.change-captcha').click(function() {
513 var time = new Date(), 571 var time = new Date(),
514 $captchaImg = $('.captcha-img'), 572 $captchaImg = $('.captcha-img'),
515 captchaImgSrc = $captchaImg.attr('src').split('?')[0]; 573 captchaImgSrc = $captchaImg.attr('src').split('?')[0];
516 574
517 $captchaImg.attr('src', captchaImgSrc + '?t=' + time.getTime()); 575 $captchaImg.attr('src', captchaImgSrc + '?t=' + time.getTime());
518 -});  
  576 + });
  577 +};
@@ -44,13 +44,13 @@ class AutouserinfoController extends AbstractAction @@ -44,13 +44,13 @@ class AutouserinfoController extends AbstractAction
44 44
45 //整合 45 //整合
46 $data = array( 46 $data = array(
47 - 'registerPage' => true, 47 + 'thirdPage' => true,
48 'simpleHeader' => $simpleHeader, 48 'simpleHeader' => $simpleHeader,
49 'passport' => array( 49 'passport' => array(
50 'actionUrl' => Helpers::url('/autouserinfo/bind'), 50 'actionUrl' => Helpers::url('/autouserinfo/bind'),
51 'region' => RegData::getAreasData(), 51 'region' => RegData::getAreasData(),
52 'location' => '+86', 52 'location' => '+86',
53 - 'captchaUrl' => Helpers::url('/passport/images?t=' . time()), 53 + 'captchaUrl' => '/passport/images?t=1449799445',
54 'itemUrl' => Helpers::url('/help/?category_id=9'), 54 'itemUrl' => Helpers::url('/help/?category_id=9'),
55 'referUrl' => $refer, 55 'referUrl' => $refer,
56 'skipUrl' => SITE_MAIN, 56 'skipUrl' => SITE_MAIN,