Authored by lore-w

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

... ... @@ -78,10 +78,21 @@
{{!-- 注册页--}}
{{#if registerPage}}
<script>
seajs.use('js/passport/reg');
seajs.use('js/passport/reg', function (reg) {
reg.init('reg');
});
</script>
{{/if}}
{{!-- 第三方登录完善信息页--}}
{{#if thirdPage}}
<script>
seajs.use('js/passport/reg', function (reg) {
reg.init('third');
});
</script>
{{/if}}
{{!-- 找回密码--}}
{{#if backPage}}
<script>
... ...
... ... @@ -83,14 +83,30 @@ validateResult = [
];
//手机号ajax校验
function phoneAjaxFn(callback) {
$.ajax({
url: '/passport/register/checkmobile',
type: 'POST',
data: {
function phoneAjaxFn(page, callback) {
var url,
data;
if (page === 'reg') {
url = '/passport/register/checkmobile';
data = {
mobile: $pn.val(),
area: $region.text().split('+')[1]
};
} else if (page === 'third') {
url = '/passport/autouserinfo/bindCheck';
data = {
mobile: $pn.val(),
area: $region.text().split('+')[1],
openId: 1,
sourceType: 'QQ'
};
}
$.ajax({
url: url,
type: 'POST',
data: data
}).then(function(data) {
switch (data.code) {
case 200:
... ... @@ -108,10 +124,17 @@ function phoneAjaxFn(callback) {
}
//图形验证码ajax校验
function picCaptchaAjaxFn(callback) {
function picCaptchaAjaxFn(page, callback) {
var url;
if (page === 'reg') {
url = '/passport/register/piccaptcha';
} else if (page === 'third') {
url = '/passport/autouserinfo/checkPicCode';
}
$.ajax({
type: 'POST',
url: '/passport/register/piccaptcha',
url: url,
data: {
code: $ca.val(),
mobile: $pn.val(),
... ... @@ -123,7 +146,7 @@ function picCaptchaAjaxFn(callback) {
validateResult[1].message = '';
validateResult[1].status = true;
break;
case 404:
case 400:
validateResult[1].message = '图形验证码错误';
validateResult[1].status = false;
break;
... ... @@ -133,10 +156,17 @@ function picCaptchaAjaxFn(callback) {
}
//短信验证码ajax校验
function msgCaptchaAjaxFn(callback) {
function msgCaptchaAjaxFn(page, callback) {
var url;
if (page === 'reg') {
url = '/passport/register/msgcaptcha';
} else if (page === 'third') {
url = '/passport/autouserinfo/checkBindMsg';
}
$.ajax({
type: 'POST',
url: '/passport/register/msgcaptcha',
url: url,
data: {
code: $ca.val(),
mobile: $pn.val(),
... ... @@ -148,7 +178,7 @@ function msgCaptchaAjaxFn(callback) {
validateResult[2].message = '';
validateResult[2].status = true;
break;
case 404:
case 400:
validateResult[2].message = '短信验证码错误';
validateResult[2].status = false;
break;
... ... @@ -159,7 +189,7 @@ function msgCaptchaAjaxFn(callback) {
}
// 验证
function validateRule($element, callback) {
function validateRule(page, $element, callback) {
var val = $.trim($element.val()),
regionCode;
... ... @@ -181,7 +211,7 @@ function validateRule($element, callback) {
callback();
} else {
phoneAjaxFn(callback);
phoneAjaxFn(page, callback);
}
//图形验证码校验
... ... @@ -200,7 +230,7 @@ function validateRule($element, callback) {
// 并且手机号正确
if (validateResult[0].status) {
picCaptchaAjaxFn(callback);
picCaptchaAjaxFn(page, callback);
} else {
validateResult[1].message = '图形验证码错误';
validateResult[1].status = false;
... ... @@ -226,7 +256,7 @@ function validateRule($element, callback) {
// 并且图形验证码正确
if (validateResult[1].status) {
msgCaptchaAjaxFn(callback);
msgCaptchaAjaxFn(page, callback);
} else {
validateResult[2].message = '短信验证码错误';
validateResult[2].status = false;
... ... @@ -379,14 +409,16 @@ function pwdFn($obj) {
// 失去焦点时开始校验
// Tips: 不可以在获得焦点的时候验证,获得焦点和失去焦点的间隔太小,如果中间存在ajax校验的话会出现问题
$registerPage.find('.va').keyup(function() {
// ( ▼-▼ )注册页和信息完善页面接口不同
exports.init = function(page) {
$registerPage.find('.va').keyup(function() {
var j,
statusLen = 0,
vLen = validateResult.length,
$that = $(this);
validateRule($(this), function() {
validateRule(page, $(this), function() {
showErrTip(); // 显示错误提示
showBorder(); // 显示红色边框
... ... @@ -422,32 +454,48 @@ $registerPage.find('.va').keyup(function() {
pwdFn($that);
}
}).blur(function() {
}).blur(function() {
/*validateRule($(this), function() {
showErrTip();
showBorder(); // 显示红色边框
});*/
});
});
$regionSelect.change(function() {
$regionSelect.change(function() {
$region.text('+' + $('#region').val());
validateRule($pn, showErrTip); //验证
});
validateRule(page, $pn, showErrTip); //验证
});
// 点击发送验证码
$sendCaptcha.click(function() {
var timeResidue = 10,
t;
// 点击发送验证码
$sendCaptcha.click(function() {
var timeResidue = 20,
t,
url;
if ($(this).hasClass('disable')) {
return;
}
//todo ajax
if (page === 'reg') {
url = '/passport/register/sendBindMsg';
} else if (page === 'third') {
url = '/passport/autouserinfo/sendBindMsg';
}
//todo ajax 发送验证码
$.ajax({
type: 'POST',
url: url,
data: {
area: $region.text().split('+')[1],
mobile: $pn.val(),
code: $ca.val()
}
}).then(function(data) {
if (data.code === 200) {
t = setInterval(function() {
if (timeResidue <= 0) {
$sendCaptcha.removeClass('disable').val('获取短信验证码');
... ... @@ -456,10 +504,20 @@ $sendCaptcha.click(function() {
}
$sendCaptcha.addClass('disable').val(timeResidue-- + '秒可重新发送');
}, 1000);
});
}
});
});
//ajax表单提交
$registerBtn.click(function() {
//form表单提交
$registerBtn.click(function() {
var url;
if (page === 'reg') {
url = '/passport/register/mobileregister';
} else if (page === 'third') {
url = '/passport/autouserinfo/bindMobile';
}
if ($(this).hasClass('disable')) {
return;
... ... @@ -468,7 +526,7 @@ $registerBtn.click(function() {
//ajax提交
$.ajax({
type: 'POST',
url: '/passport/register/mobileregister',
url: url,
data: {
area: $region.text().split('+')[1],
mobile: $pn.val(),
... ... @@ -507,12 +565,13 @@ $registerBtn.click(function() {
});
}
});
});
$('.change-captcha').click(function() {
$('.change-captcha').click(function() {
var time = new Date(),
$captchaImg = $('.captcha-img'),
captchaImgSrc = $captchaImg.attr('src').split('?')[0];
$captchaImg.attr('src', captchaImgSrc + '?t=' + time.getTime());
});
\ No newline at end of file
});
};
\ No newline at end of file
... ...
... ... @@ -44,13 +44,13 @@ class AutouserinfoController extends AbstractAction
//整合
$data = array(
'registerPage' => true,
'thirdPage' => true,
'simpleHeader' => $simpleHeader,
'passport' => array(
'actionUrl' => Helpers::url('/autouserinfo/bind'),
'region' => RegData::getAreasData(),
'location' => '+86',
'captchaUrl' => Helpers::url('/passport/images?t=' . time()),
'captchaUrl' => '/passport/images?t=1449799445',
'itemUrl' => Helpers::url('/help/?category_id=9'),
'referUrl' => $refer,
'skipUrl' => SITE_MAIN,
... ...