verification.js
2.41 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
/**
* 验证手机
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/12/14
*/
var $ = require('yoho-jquery');
var $smsCaptchaCtrl = $('#send-captcha'),
$next = $('#next-step'),
$smsCaptchaInput = $('#captcha');
var second = 60;
var $errTip = $('.tips'),
$errMsg = $errTip.find('.rectangle');
function errTip(ele, msg) {
var topLeft = ele.offset();
$errMsg.text(msg);
return $errTip.css({
top: topLeft.top + ele.height() - 2,
left: topLeft.left,
width: ele.width() + 2,
height: ele.height
}).removeClass('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('获取短信验证码');
$smsCaptchaCtrl.removeClass('disable');
} else {
$smsCaptchaCtrl.text(second + '秒后可重新操作');
window.setTimeout(disableSMSBtn, 1000);
}
}
$smsCaptchaCtrl.click(function() {
if ($smsCaptchaCtrl.hasClass('disable')) {
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);
} else {
$next.addClass('disable');
errTip($smsCaptchaInput, '验证码不正确');
}
}
});
} else {
errTip($smsCaptchaInput, '验证码不正确');
$next.addClass('disable').attr('href', 'javascript:;');
}
});
function init() {
$smsCaptchaCtrl.addClass('disable');
disableSMSBtn();
}
init();