...
|
...
|
@@ -9,7 +9,7 @@ var EventProxy = require('../common/eventproxy'); |
|
|
|
|
|
var $phoneNumInput = $('#account'),
|
|
|
$passwordInput = $('#password'),
|
|
|
$captchaInput = $('#captcha'),
|
|
|
$imgCaptchaInput = $('#captcha'),
|
|
|
$loginBtn = $('#login-btn'),
|
|
|
$phone = $('#phone');
|
|
|
|
...
|
...
|
@@ -37,8 +37,6 @@ var checkbox = { |
|
|
unchecked: ''
|
|
|
};
|
|
|
|
|
|
var emailAcTime;
|
|
|
|
|
|
var $errTip = $('.tips');
|
|
|
var $errMsg = $errTip.find('.rectangle');
|
|
|
|
...
|
...
|
@@ -56,7 +54,6 @@ function errTip(ele, msg) { |
|
|
}).removeClass('hide');
|
|
|
}
|
|
|
|
|
|
|
|
|
// 验证账户名
|
|
|
function validateAccountLocal() {
|
|
|
var phoneNum = $.trim($phoneNumInput.val()),
|
...
|
...
|
@@ -66,7 +63,6 @@ function validateAccountLocal() { |
|
|
if (/^[0-9]+$/.test(phoneNum)) {
|
|
|
// 不是11位
|
|
|
if (phoneNum.length !== 11) {
|
|
|
ep.emit('phone', false);
|
|
|
errTip($phone, '手机号码不正确,请重新输入');
|
|
|
return false;
|
|
|
}
|
...
|
...
|
@@ -74,10 +70,8 @@ function validateAccountLocal() { |
|
|
// 如果是纯数字,则作为手机号码处理
|
|
|
if (regionCode !== '+86' ||
|
|
|
mailPhoneRegx.phoneRegx[regionCode].test(phoneNum)) {
|
|
|
ep.emit('phone', true);
|
|
|
return true;
|
|
|
} else {
|
|
|
ep.emit('phone', false);
|
|
|
errTip($phone, '手机号码不正确,请重新输入');
|
|
|
return false;
|
|
|
}
|
...
|
...
|
@@ -85,17 +79,14 @@ function validateAccountLocal() { |
|
|
|
|
|
// 邮箱验证
|
|
|
if (mailPhoneRegx.emailRegx.test(phoneNum)) {
|
|
|
ep.emit('phone', true);
|
|
|
return true;
|
|
|
} else {
|
|
|
ep.emit('phone', false);
|
|
|
errTip($phone, '邮箱格式不正确,请重新输入');
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
ep.emit('phone', false);
|
|
|
errTip($phone, '请输入账号');
|
|
|
return false;
|
|
|
}
|
...
|
...
|
@@ -111,10 +102,8 @@ function validateAccountAsync() { |
|
|
}
|
|
|
}).then(function(data) {
|
|
|
if (data.code && data.code === 200) {
|
|
|
ep.emit('phone', true);
|
|
|
return true;
|
|
|
} else {
|
|
|
ep.emit('phone', false);
|
|
|
errTip($phone, '账号不存在');
|
|
|
return false;
|
|
|
}
|
...
|
...
|
@@ -122,17 +111,29 @@ function validateAccountAsync() { |
|
|
}
|
|
|
|
|
|
function validateAccount() {
|
|
|
function validate() {
|
|
|
var defer = $.Deferred(); // eslint-disable-line
|
|
|
|
|
|
if (validateAccountLocal()) {
|
|
|
validateAccountAsync().then(function(result) {
|
|
|
if (result) {
|
|
|
defer.resolve(result);
|
|
|
} else {
|
|
|
defer.reject(result);
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
defer.resolve(false);
|
|
|
defer.reject(false);
|
|
|
}
|
|
|
|
|
|
return defer.promise();
|
|
|
}
|
|
|
|
|
|
return validate().then(function() {
|
|
|
ep.emit('phone', true);
|
|
|
}).fail(function() {
|
|
|
ep.emit('phone', false);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 验证密码
|
...
|
...
|
@@ -158,7 +159,7 @@ function validatePasswordLocal() { |
|
|
|
|
|
// 验证验证码
|
|
|
function validateCaptchaLocal() {
|
|
|
var captcha = $.trim($captchaInput.val());
|
|
|
var captcha = $.trim($imgCaptchaInput.val());
|
|
|
var length = captcha.length;
|
|
|
|
|
|
if ($captchaWrap.hasClass('hide')) {
|
...
|
...
|
@@ -168,14 +169,14 @@ function validateCaptchaLocal() { |
|
|
|
|
|
switch (length) {
|
|
|
case 0:
|
|
|
errTip($captchaInput, '请输入验证码');
|
|
|
errTip($imgCaptchaInput, '请输入验证码');
|
|
|
ep.emit('captcha', false);
|
|
|
break;
|
|
|
case 4:
|
|
|
ep.emit('captcha', true);
|
|
|
break;
|
|
|
default:
|
|
|
errTip($captchaInput, '请输入长度为4字符的验证码');
|
|
|
errTip($imgCaptchaInput, '请输入长度为4字符的验证码');
|
|
|
ep.emit('captcha', false);
|
|
|
break;
|
|
|
}
|
...
|
...
|
@@ -185,7 +186,7 @@ function validateCaptchaLocal() { |
|
|
function showAccountErrTimes() {
|
|
|
$captchaWrap.removeClass('hide');
|
|
|
$captchaImg.attr('src', captchaUrl + $.now());
|
|
|
$captchaInput.val('');
|
|
|
$imgCaptchaInput.val('');
|
|
|
}
|
|
|
|
|
|
// 登录
|
...
|
...
|
@@ -197,7 +198,7 @@ function login() { |
|
|
areaCode: $regionCodeText.text().replace('+', ''),
|
|
|
account: $.trim($phoneNumInput.val()),
|
|
|
password: $.trim($passwordInput.val()),
|
|
|
captcha: $.trim($captchaInput.val()),
|
|
|
captcha: $.trim($imgCaptchaInput.val()),
|
|
|
isRemember: $remember.hasClass('checked') ? true : false
|
|
|
},
|
|
|
success: function(res) {
|
...
|
...
|
@@ -209,7 +210,7 @@ function login() { |
|
|
}
|
|
|
} else {
|
|
|
if (res.data.errorType === 'captcha') {
|
|
|
$captchaInput.val('');
|
|
|
$imgCaptchaInput.val('');
|
|
|
} else {
|
|
|
$loginTip.removeClass('hide').children('em').html(res.message);
|
|
|
$passwordInput.val('');
|
...
|
...
|
@@ -225,7 +226,7 @@ function login() { |
|
|
}
|
|
|
|
|
|
mailAc($phoneNumInput, function() {
|
|
|
function validateUser() {
|
|
|
function throttle() {
|
|
|
return $.ajax({
|
|
|
url: '/passport/login/account',
|
|
|
type: 'GET',
|
...
|
...
|
@@ -237,7 +238,7 @@ mailAc($phoneNumInput, function() { |
|
|
|
|
|
validateAccount().then(function(result) {
|
|
|
if (result) {
|
|
|
return validateUser();
|
|
|
return throttle();
|
|
|
} else {
|
|
|
return false;
|
|
|
}
|
...
|
...
|
@@ -260,6 +261,7 @@ $phoneNumInput.on('focus', function() { |
|
|
|
|
|
$('[placeholder]').placeholder();
|
|
|
|
|
|
// 选择地点
|
|
|
$regionSelectCtrl.change(function() {
|
|
|
var $this = $(this);
|
|
|
|
...
|
...
|
@@ -270,22 +272,20 @@ $regionSelectCtrl.change(function() { |
|
|
$passwordInput.on('blur', function() {
|
|
|
$passwordInput.removeClass('focus');
|
|
|
validatePasswordLocal();
|
|
|
$captchaInput.trigger('blur');
|
|
|
}).on('focus', function() {
|
|
|
$passwordInput.addClass('focus');
|
|
|
});
|
|
|
|
|
|
// 验证码
|
|
|
$captchaInput.on('blur', function() {
|
|
|
$captchaInput.removeClass('focus');
|
|
|
$imgCaptchaInput.on('blur', function() {
|
|
|
$imgCaptchaInput.removeClass('focus');
|
|
|
validateCaptchaLocal();
|
|
|
}).on('focus', function() {
|
|
|
$captchaInput.addClass('focus');
|
|
|
$imgCaptchaInput.addClass('focus');
|
|
|
});
|
|
|
|
|
|
// 邮箱自动完成列表项点击
|
|
|
$emailAutoComplete.on('click', 'li', function() {
|
|
|
clearTimeout(emailAcTime); // 清空默认关闭
|
|
|
$phoneNumInput.val($(this).text()).focus();
|
|
|
$emailAutoComplete.addClass('hide');
|
|
|
});
|
...
|
...
|
@@ -303,13 +303,6 @@ $remember.on('click', function() { |
|
|
}
|
|
|
});
|
|
|
|
|
|
// focus到输入框则隐藏错误提示和样式
|
|
|
$('.va').on('focus', function() {
|
|
|
var $this = $(this);
|
|
|
|
|
|
$this.siblings('.err-tip').addClass('hide');
|
|
|
});
|
|
|
|
|
|
// 验证码刷新
|
|
|
$captchaWrap.on('click', '.change-captcha, .captcha-img', function() {
|
|
|
$captchaImg.attr('src', captchaUrl + $.now());
|
...
|
...
|
@@ -363,3 +356,5 @@ $('input.va').on('keypress', function(e) { |
|
|
}
|
|
|
});
|
|
|
|
|
|
// 首次触发
|
|
|
$imgCaptchaInput.trigger('blur'); |
...
|
...
|
|