sms-password.page.js
1.68 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
var tip = require('plugin/tip');
var $eyeBtn,
$pwd,
$nextBtn;
var page = {
disableAjax: false,
init: function() {
this.domInit();
this.bindEvent();
},
domInit: function() {
$eyeBtn = $('#eye');
$pwd = $('#pwd');
$nextBtn = $('#btn-next');
},
bindEvent: function() {
var self = this;
$eyeBtn.on('click', function() {
self.togglePassword();
});
$nextBtn.on('click', function() {
!self.disableAjax && self.setPasswordAndLogin();
});
$pwd.on('input', function() {
var bool = Boolean($.trim(this.value));
$nextBtn
.toggleClass('disable', !bool)
.prop('disable', !bool);
});
},
togglePassword: function() {
var bool = $eyeBtn.hasClass('close');
$eyeBtn.toggleClass(function() {
$pwd.attr('type', !bool ? 'password' : 'text');
return 'close';
}, !bool);
},
setPasswordAndLogin: function() {
var self = this;
var password = $.trim($pwd.val());
this.disableAjax = true;
$.post('/passport/sms_login/password.json', {
password: password
})
.done(function(res) {
if (res.code === 200) {
location.href = res.redirect;
return;
}
tip.show(res.message);
})
.fail(function() {
tip.show('出错了, 请重试');
})
.always(function() {
self.disableAjax = false;
});
}
};
$(function() {
page.init();
});