frontend.js
2.9 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
define(['fast'], function (Fast) {
var Frontend = {
api: Fast.api,
init: function () {
//发送邮箱验证码
$(document).on("click", ".btn-email", function (e) {
var email = $(this).closest("form").find("#email");
if (email.val() == "") {
Layer.alert("邮箱不能为空!");
return false;
}
var that = this;
email.isValid(function (v) {
if (v) {
Frontend.api.ajax({url: "sms/sendemail", data: {type: $(that).data("type"), email: email.val()}}, function () {
$(that).val("已发送");
});
} else {
Layer.alert("请确认已经输入了正解的邮箱!");
}
});
return false;
});
//发送手机验证码
$(document).on("click", ".btn-captcha", function (e) {
var mobile = $(this).closest("form").find("#mobile");
if (mobile.val() == "") {
Layer.alert("手机号码不能为空!");
return false;
} else if (!mobile.val().match(/^1[3-9]\d{9}$/)) {
Layer.alert("请输入正确的手机号码!");
return false;
}
var that = this;
mobile.isValid(function (v) {
if (v) {
$(that).addClass("disabled", true).text("获取中...");
var si;
Frontend.api.ajax({url: "sms/send", data: {type: $(that).data("type"), mobile: mobile.val()}}, function () {
Layer.msg("验证码已发送");
clearInterval(si);
var seconds = 60;
si = setInterval(function () {
seconds--;
if (seconds <= 0) {
clearInterval(si);
$(that).removeClass("disabled", false).text("获取验证码");
} else {
$(that).addClass("disabled", true).text(seconds + "秒后可再次发送");
}
}, 1000);
});
} else {
Layer.alert("请确认已经输入了正解的手机号!");
}
});
return false;
});
}
};
Frontend.api = $.extend(Fast.api, Frontend.api);
//将Frontend渲染至全局,以便于在子框架中调用
window.Frontend = Frontend;
Frontend.init();
return Frontend;
});