user.js
4.0 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
define(['jquery', 'bootstrap', 'frontend', 'form', 'template'], function ($, undefined, Frontend, Form, Template) {
var validatoroptions = {
invalid: function (form, errors) {
$.each(errors, function (i, j) {
Layer.msg(j);
});
}
};
var Controller = {
login: function () {
//本地验证未通过时提示
$("#login-form").data("validator-options", validatoroptions);
$(document).on("change", "input[name=type]", function () {
var type = $(this).val();
$("div.form-group[data-type]").addClass("hide");
$("div.form-group[data-type='" + type + "']").removeClass("hide");
$('#resetpwd-form').validator("setField", {
captcha: "required;length(4);integer[+];remote(" + $(this).data("check-url") + ", event=resetpwd, " + type + ":#" + type + ")",
});
$(".btn-captcha").data("url", $(this).data("send-url")).data("type", type);
});
//为表单绑定事件
Form.api.bindevent($("#login-form"), function (data, ret) {
setTimeout(function () {
location.href = ret.url ? ret.url : "/";
}, 1000);
});
Form.api.bindevent($("#resetpwd-form"), function (data) {
Layer.closeAll();
});
$(document).on("click", ".btn-forgot", function () {
var id = "resetpwdtpl";
var content = Template(id, {});
Layer.open({
type: 1,
title: __('Reset password'),
area: ["450px", "355px"],
content: content,
success: function (layero) {
Form.api.bindevent($("#resetpwd-form", layero), function (data) {
Layer.closeAll();
});
}
});
});
},
register: function () {
//本地验证未通过时提示
$("#register-form").data("validator-options", validatoroptions);
//为表单绑定事件
Form.api.bindevent($("#register-form"), function (data, ret) {
setTimeout(function () {
location.href = ret.url ? ret.url : "/";
}, 1000);
});
},
changepwd: function () {
//本地验证未通过时提示
$("#changepwd-form").data("validator-options", validatoroptions);
//为表单绑定事件
Form.api.bindevent($("#changepwd-form"), function (data, ret) {
setTimeout(function () {
location.href = ret.url ? ret.url : "/";
}, 1000);
});
},
profile: function () {
// 给上传按钮添加上传成功事件
$("#plupload-avatar").data("upload-success", function (data) {
var url = Fast.api.cdnurl(data.url);
$(".profile-user-img").prop("src", url);
Toastr.success(__('Upload successful'));
});
Form.api.bindevent($("#profile-form"));
$(document).on("click", ".btn-change", function () {
var that = this;
var id = $(this).data("type") + "tpl";
var content = Template(id, {});
Layer.open({
type: 1,
title: "修改",
area: ["400px", "250px"],
content: content,
success: function (layero) {
var form = $("form", layero);
Form.api.bindevent(form, function (data) {
location.reload();
Layer.closeAll();
});
}
});
});
}
};
return Controller;
});