Authored by 郭成尧

international-login-ok

import $ from 'yoho-jquery';
import tip from 'plugin/tip';
import Page from 'yoho-page';
import api from '../api';
import Validate from 'plugin/validata';
const showErrTip = tip.show;
const trim = $.trim;
const $captcha = $('#js-img-check');
const useVerify = $captcha.data('userverify'); // 170406 是否使用验证
let validate = {};
if (useVerify) {
validate = new Validate($captcha, {
useREM: {
rootFontSize: 40,
picWidth: 150
}
});
validate.init();
}
class InternationalNew extends Page {
constructor() {
super();
this.selector = {
countryCodeSelector: $('#countryCodeSelector'),
clearMobile: $('#clearMobile'),
mobileInput: $('input[name=mobile]'),
passwordInput: $('input[name=password]'),
... ... @@ -42,10 +64,79 @@ class InternationalNew extends Page {
}
/**
* 国际账号登录
* 登录操作处理
*/
internationalLogin() {
let pn = trim(this.selector.mobileInput.val()),
areaCode = this.selector.countryCodeSelector.val(),
pwd = trim(this.selector.passwordInput.val());
if (!this.selector.internationalLoginBtn.hasClass('active')) {
return;
}
if ((api.phoneRegx[areaCode].test(pn) || areaCode !== '+86') && api.pwdValidate(pwd)) {
let params = {
areaCode: areaCode.replace('+', ''),
account: pn,
password: pwd
};
if (useVerify) {
validate.getResults().then((result) => {
this.selector.internationalLoginBtn.text('正在登录...').addClass('disable');
$.extend(params, result);
this.postInternationalLogin(params);
});
} else {
this.postInternationalLogin(params);
}
} else {
showErrTip('账号或密码有错误,请重新输入');
this.selector.internationalLoginBtn.text('登录').addClass('disable');
}
}
/**
* 发送国际账号登录请求
*/
postInternationalLogin(params) {
this.ajax({
type: 'POST',
url: '/passport/login/auth',
data: params
}).then(data => {
let res;
validate && validate.type === 2 && validate.refresh();
if (data.code === 200) {
res = data.data;
showErrTip('登录成功');
// 3秒后强制跳转
setTimeout(() => {
location.href = res.href;
}, 1500);
this.selector.internationalLoginBtn.text('登录成功');
showErrTip('登录成功');
} else {
if (useVerify && data.captchaShow) {
((data.changeCaptcha && validate.type !== 2) && validate.refresh());
}
showErrTip(data.message);
this.resetForm();
}
});
}
/**
* 重置表单
*/
resetForm() {
this.selector.passwordInput.val('').focus();
this.selector.internationalLoginBtn.text('登录').removeClass('active');
}
/**
... ...