interational.js
2.44 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
/**
* 国际账号登录
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/10/8
*/
var $ = require('yoho.zepto');
var $phoneNum = $('#phone-num'),
$countrySelect = $('#country-select'),
$countryCode = $('#country-code'),
$pwd = $('#pwd'),
$loginBtn = $('#btn-login'),
pnPass = false,
pwdPass = false;
var api = require('../api');
var tip = require('../../plugin/tip');
var trim = $.trim;
var showErrTip = tip.show;
//登录按钮状态切换
function switchLoginBtnStatus() {
if (pnPass && pwdPass) {
$loginBtn.removeClass('disable');
} else {
$loginBtn.addClass('disable');
}
}
//Android-UC下显示select的direction:rtl无效的临时解决办法
api.selectCssHack($countrySelect);
//显示隐藏密码
api.bindEyesEvt();
//清空手机号码
api.bindClearEvt();
$phoneNum.bind('input', function() {
if (trim($phoneNum.val()) === '') {
pnPass = false;
} else {
pnPass = true;
}
switchLoginBtnStatus();
});
$pwd.bind('input', function() {
var pwd = trim($pwd.val());
if (pwd === '') {
pwdPass = false;
} else {
pwdPass = true;
}
switchLoginBtnStatus();
});
$countrySelect.change(function() {
$countryCode.text($countrySelect.val());
});
$loginBtn.on('touchstart', function() {
var pn = trim($phoneNum.val()),
country = $countrySelect.val(),
pwd = trim($pwd.val());
if ($loginBtn.hasClass('disable')) {
return;
}
if (api.phoneRegx[country].test(pn) && api.pwdValidate(pwd)) {
$.ajax({
type: 'POST',
url: '/passport/signin/auth',
data: {
areaCode: country.split('+')[1],
phoneNum: pn,
password: pwd
},
success: function(data) {
if (data.code === 200) {
showErrTip('登录成功');
//1000ms后跳转页面
setTimeout(function() {
location.href = data.data;
}, 1000);
} else {
showErrTip(data.message);
}
},
error: function() {
showErrTip('网络断开连接啦~');
}
});
} else {
showErrTip('账号或密码有错误,请重新输入');
}
});
//对初始有默认值的情况去初始化登录按钮状态
$phoneNum.trigger('input');
$pwd.trigger('input');