frontend.js
4.1 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
define(['fast', 'template', 'moment'], function (Fast, Template, Moment) {
var Frontend = {
api: Fast.api,
init: function () {
var si = {};
//发送验证码
$(document).on("click", ".btn-captcha", function (e) {
var type = $(this).data("type") ? $(this).data("type") : 'mobile';
var btn = this;
Frontend.api.sendcaptcha = function (btn, type, data, callback) {
$(btn).addClass("disabled", true).text("发送中...");
Frontend.api.ajax({url: $(btn).data("url"), data: data}, function (data, ret) {
clearInterval(si[type]);
var seconds = 60;
si[type] = setInterval(function () {
seconds--;
if (seconds <= 0) {
clearInterval(si);
$(btn).removeClass("disabled").text("发送验证码");
} else {
$(btn).addClass("disabled").text(seconds + "秒后可再次发送");
}
}, 1000);
if (typeof callback == 'function') {
callback.call(this, data, ret);
}
}, function () {
$(btn).removeClass("disabled").text('发送验证码');
});
};
if (['mobile', 'email'].indexOf(type) > -1) {
var element = $(this).data("input-id") ? $("#" + $(this).data("input-id")) : $("input[name='" + type + "']", $(this).closest("form"));
var text = type === 'email' ? '邮箱' : '手机号码';
if (element.val() === "") {
Layer.msg(text + "不能为空!");
element.focus();
return false;
} else if (type === 'mobile' && !element.val().match(/^1[3-9]\d{9}$/)) {
Layer.msg("请输入正确的" + text + "!");
element.focus();
return false;
} else if (type === 'email' && !element.val().match(/^[\w\+\-]+(\.[\w\+\-]+)*@[a-z\d\-]+(\.[a-z\d\-]+)*\.([a-z]{2,4})$/)) {
Layer.msg("请输入正确的" + text + "!");
element.focus();
return false;
}
element.isValid(function (v) {
if (v) {
var data = {event: $(btn).data("event")};
data[type] = element.val();
Frontend.api.sendcaptcha(btn, type, data);
} else {
Layer.msg("请确认已经输入了正确的" + text + "!");
}
});
} else {
var data = {event: $(btn).data("event")};
Frontend.api.sendcaptcha(btn, type, data, function (data, ret) {
Layer.open({title: false, area: ["400px", "430px"], content: "<img src='" + data.image + "' width='400' height='400' /><div class='text-center panel-title'>扫一扫关注公众号获取验证码</div>", type: 1});
});
}
return false;
});
//tooltip和popover
if (!('ontouchstart' in document.documentElement)) {
$('body').tooltip({selector: '[data-toggle="tooltip"]'});
}
$('body').popover({selector: '[data-toggle="popover"]'});
}
};
Frontend.api = $.extend(Fast.api, Frontend.api);
//将Template渲染至全局,以便于在子框架中调用
window.Template = Template;
//将Moment渲染至全局,以便于在子框架中调用
window.Moment = Moment;
//将Frontend渲染至全局,以便于在子框架中调用
window.Frontend = Frontend;
Frontend.init();
return Frontend;
});