verification.js
2.65 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
/**
* 验证手机
* @author: TaoHuang
* @date: 2016/7/14
*/
var $ = require('yoho-jquery');
var $smsCaptchaCtrl = $('#send-captcha'),
$next = $('#next-step'),
$smsCaptchaInput = $('#captcha');
var second = 60;
function errTip(ele, msg) {
var $errTip = ele.next('.tips');
var $errMsg = $errTip.find('.content');
$errMsg.text(msg);
return $errTip.removeClass('hide');
}
function hideTip(ele) {
return ele.next('.tips').addClass('hide');
}
// 发送短信验证码
function sendSMSCaptchaAsync() {
return $.post('/passport/back/sendbackmobile', {
mobile: $('#mobile').val(),
area: $('#area').val(),
verifyCode: $('#captchaPic').val()
});
}
function disableSMSBtn() {
second -= 1;
if (second < 0) {
second = 60;
$smsCaptchaCtrl.text('获取短信验证码').removeClass('disable').removeClass('second-progress');
} else {
$smsCaptchaCtrl.addClass('second-progress').text(second + '秒后可重新操作');
window.setTimeout(disableSMSBtn, 1000);
}
}
$smsCaptchaCtrl.click(function() {
if ($smsCaptchaCtrl.hasClass('disable') || $smsCaptchaCtrl.hasClass('second-progress')) {
return;
}
$smsCaptchaCtrl.addClass('disable');
disableSMSBtn();
sendSMSCaptchaAsync();
});
$smsCaptchaInput.on('blur', function() {
var v = $.trim($(this).val());
if (v === '') {
errTip($smsCaptchaInput, '请输入短信验证码');
return;
}
if (v.length === 4) {
$.ajax({
type: 'POST',
url: '/passport/back/backmobile',
dataType: 'json',
data: {
code: $('#captcha').val(),
verifyCode: $('#captchaPic').val(),
area: $('#area').val(),
mobile: $('#mobile').val()
},
success: function(res) {
if (res.code === 200) {
// 添加验证码正确验证
$next.removeClass('disable').attr('href', res.data);
hideTip($smsCaptchaInput);
} else {
$next.addClass('disable');
errTip($smsCaptchaInput, '验证码不正确');
}
}
});
} else {
errTip($smsCaptchaInput, '验证码不正确');
$next.addClass('disable').attr('href', 'javascript:;'); // eslint-disable-line
}
}).on('focus', function() {
hideTip($smsCaptchaInput);
$smsCaptchaInput.addClass('focus');
}).on('blur', function() {
$smsCaptchaInput.removeClass('focus');
});
function init() {
$smsCaptchaCtrl.addClass('disable');
disableSMSBtn();
}
init();