user.js
9.2 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
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);
//为表单绑定事件
Form.api.bindevent($("#login-form"), function (data, ret) {
setTimeout(function () {
location.href = ret.url ? ret.url : "/";
}, 1000);
});
//忘记密码
$(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) {
var rule = $("#resetpwd-form input[name='captcha']").data("rule");
Form.api.bindevent($("#resetpwd-form", layero), function (data) {
Layer.closeAll();
});
$(layero).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: rule.replace(/remote\((.*)\)/, "remote(" + $(this).data("check-url") + ", event=resetpwd, " + type + ":#" + type + ")")
});
$(".btn-captcha").data("url", $(this).data("send-url")).data("type", type);
});
}
});
});
},
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);
}, function (data) {
$("input[name=captcha]").next(".input-group-btn").find("img").trigger("click");
});
},
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 () {
// 给上传按钮添加上传成功事件
$("#faupload-avatar").data("upload-success", function (data) {
var url = Fast.api.cdnurl(data.url);
$(".profile-user-img").prop("src", url);
Toastr.success(__('Uploaded 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();
});
}
});
});
},
attachment: function () {
require(['table'], function (Table) {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'user/attachment',
}
});
var urlArr = [];
var multiple = Fast.api.query('multiple');
multiple = multiple == 'true' ? true : false;
var table = $("#table");
table.on('check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table', function (e, row) {
if (e.type == 'check' || e.type == 'uncheck') {
row = [row];
} else {
urlArr = [];
}
$.each(row, function (i, j) {
if (e.type.indexOf("uncheck") > -1) {
var index = urlArr.indexOf(j.url);
if (index > -1) {
urlArr.splice(index, 1);
}
} else {
urlArr.indexOf(j.url) == -1 && urlArr.push(j.url);
}
});
});
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
sortName: 'id',
showToggle: false,
showExport: false,
fixedColumns: true,
fixedRightNumber: 1,
columns: [
[
{field: 'state', checkbox: multiple, visible: multiple, operate: false},
{field: 'id', title: __('Id'), operate: false},
{
field: 'url', title: __('Preview'), formatter: function (value, row, index) {
var html = '';
if (row.mimetype.indexOf("image") > -1) {
html = '<a href="' + row.fullurl + '" target="_blank"><img src="' + row.fullurl + row.thumb_style + '" alt="" style="max-height:60px;max-width:120px"></a>';
} else {
html = '<a href="' + row.fullurl + '" target="_blank"><img src="' + Fast.api.fixurl("ajax/icon") + "?suffix=" + row.imagetype + '" alt="" style="max-height:90px;max-width:120px"></a>';
}
return '<div style="width:120px;margin:0 auto;text-align:center;overflow:hidden;white-space: nowrap;text-overflow: ellipsis;">' + html + '</div>';
}
},
{
field: 'filename', title: __('Filename'), formatter: function (value, row, index) {
return '<div style="width:150px;margin:0 auto;text-align:center;overflow:hidden;white-space: nowrap;text-overflow: ellipsis;">' + Table.api.formatter.search.call(this, value, row, index) + '</div>';
}, operate: 'like'
},
{field: 'imagewidth', title: __('Imagewidth'), operate: false},
{field: 'imageheight', title: __('Imageheight'), operate: false},
{field: 'mimetype', title: __('Mimetype'), formatter: Table.api.formatter.search},
{field: 'createtime', title: __('Createtime'), width: 120, formatter: Table.api.formatter.datetime, datetimeFormat: 'YYYY-MM-DD', operate: 'RANGE', addclass: 'datetimerange', sortable: true},
{
field: 'operate', title: __('Operate'), width: 85, events: {
'click .btn-chooseone': function (e, value, row, index) {
Fast.api.close({url: row.url, multiple: multiple});
},
}, formatter: function () {
return '<a href="javascript:;" class="btn btn-danger btn-chooseone btn-xs"><i class="fa fa-check"></i> ' + __('Choose') + '</a>';
}
}
]
]
});
// 选中多个
$(document).on("click", ".btn-choose-multi", function () {
Fast.api.close({url: urlArr.join(","), multiple: multiple});
});
// 为表格绑定事件
Table.api.bindevent(table);
require(['upload'], function (Upload) {
Upload.api.upload($("#toolbar .faupload"), function () {
$(".btn-refresh").trigger("click");
});
});
});
}
};
return Controller;
});