international-new.js
5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
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 是否使用验证
const validate = new Validate($captcha, {
useREM: {
rootFontSize: 40,
picWidth: 150
}
});
class InternationalNew extends Page {
constructor() {
super();
this.selector = {
countryCodeSelector: $('#countryCodeSelector'),
clearMobile: $('#clearMobile'),
mobileInput: $('input[name=mobile]'),
passwordInput: $('input[name=password]'),
passwordEyeIcon: $('#passwordEyeIcon'),
eyeClose: $('.eye-close'),
eyeOpen: $('.eye-open'),
internationalLoginBtn: $('#internationalLoginBtn')
};
this.init();
}
init() {
if ($captcha.data('userverify')) {
validate.init();
}
this.bindEvents();
}
bindEvents() {
this.selector.clearMobile.on('click', this.clearMobile.bind(this));
this.selector.passwordEyeIcon.on('click', this.passwordShowStatus.bind(this));
this.selector.internationalLoginBtn.on('click', this.internationalLogin.bind(this));
this.selector.mobileInput.bind('input', this.changeLoginBtnStatus.bind(this, 'mobile'));
this.selector.passwordInput.bind('input', this.changeLoginBtnStatus.bind(this));
}
/**
* 改变登录按钮的状态
* which
*/
changeLoginBtnStatus(which) {
if (which === 'mobile') {
// 清除手机号按钮
if (this.selector.mobileInput.val()) {
this.selector.clearMobile.removeClass('hide');
} else {
this.selector.clearMobile.addClass('hide');
}
}
// 登录按钮
if (this.selector.mobileInput.val() && this.selector.passwordInput.val()) {
this.selector.internationalLoginBtn.addClass('active');
} else {
this.selector.internationalLoginBtn.removeClass('active');
}
}
/**
* 登录操作处理
*/
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 {
$captcha.data('userverify', data.captchaShow);
if (data.captchaShow) {
if (validate.atWorking) {
((data.changeCaptcha && validate.type !== 2) && validate.refresh());
} else {
validate.init();
}
}
showErrTip(data.message);
this.resetForm();
}
});
}
/**
* 重置表单
*/
resetForm() {
this.selector.passwordInput.val('').focus();
this.selector.internationalLoginBtn.text('登录').removeClass('active');
}
/**
* 隐藏显示密码
*/
passwordShowStatus() {
if (this.selector.eyeOpen.hasClass('hide')) {
this.selector.passwordInput.attr('type', 'text');
this.selector.eyeClose.addClass('hide');
this.selector.eyeOpen.removeClass('hide');
} else {
this.selector.passwordInput.attr('type', 'password');
this.selector.eyeOpen.addClass('hide');
this.selector.eyeClose.removeClass('hide');
}
}
/**
* 清除输入的手机号
*/
clearMobile() {
this.selector.mobileInput.val('');
this.selector.clearMobile.addClass('hide');
}
}
module.exports = InternationalNew;