forked from liaoshengping/myJsNote
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.js
More file actions
182 lines (166 loc) · 4.24 KB
/
Copy pathadmin.js
File metadata and controls
182 lines (166 loc) · 4.24 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
/**
* 后台JS主入口
*/
var layer = layui.layer,
element,
laydate = layui.laydate;
/**
* AJAX全局设置
*/
$.ajaxSetup({
type: "post",
dataType: "json"
});
layui.use('element', function(){
element = layui.element;
});
/**
* 后台侧边菜单选中状态
*/
$('.layui-nav-item').find('a').removeClass('layui-this');
$('.layui-nav-tree').find('a[href*="' + GV.current_controller + '"]').parent().addClass('layui-this').parents('.layui-nav-item').addClass('layui-nav-itemed');
/**
* 通用单图上传
*/
/*layui.upload({
url: "/index.php/api/upload/upload",
type: 'image',
ext: 'jpg|png|gif|bmp',
success: function (data) {
if (data.error === 0) {
document.getElementById('thumb').value = data.url;
} else {
layer.msg(data.message);
}
}
});*/
layui.use('upload', function(){
var upload = layui.upload;
upload.render({
elem: '.thumb',
url: '/index.php/api/upload/upload',
accept: 'images',
ext: 'jpg|png|gif|bmp|jpeg',
done: function(res){
if (res.error === 0) {
$(this)[0].elem.css('background-image', 'url("' + res.url + '")');
$(this)[0].elem.find('input').val(res.url);
} else {
layer.msg(res.message);
}
}
});
});
/**
* 通用日期时间选择
*/
$('.datetime').on('click', function () {
laydate({
elem: this,
istime: true,
format: 'YYYY-MM-DD hh:mm:ss'
})
});
/**
* 通用表单提交(AJAX方式)
*/
var form = "";
layui.use('form', function(){
form = layui.form;
form.on('submit(*)', function (data) {
$.ajax({
url: data.form.action,
type: data.form.method,
data: $(data.form).serialize(),
success: function (info) {
if (info.code === 1) {
setTimeout(function () {
location.href = info.url;
}, 1000);
}
layer.msg(info.msg);
}
});
return false;
});
});
/**
* 通用批量处理(审核、取消审核、删除)
*/
$('.ajax-action').on('click', function () {
var _action = $(this).data('action');
layer.open({
shade: false,
content: '确定执行此操作?',
btn: ['确定', '取消'],
yes: function (index) {
$.ajax({
url: _action,
data: $('.ajax-form').serialize(),
success: function (info) {
if (info.code === 1) {
setTimeout(function () {
location.href = info.url;
}, 1000);
}
layer.msg(info.msg);
}
});
layer.close(index);
}
});
return false;
});
/**
* 通用全选
*/
$('.check-all').on('click', function () {
$(this).parents('table').find('input[type="checkbox"]').prop('checked', $(this).prop('checked'));
});
/**
* 通用删除
*/
$('.ajax-delete').on('click', function () {
var _href = $(this).attr('href');
layer.open({
shade: false,
content: '确定删除?',
btn: ['确定', '取消'],
yes: function (index) {
$.ajax({
url: _href,
type: "get",
success: function (info) {
if (info.code === 1) {
setTimeout(function () {
location.href = info.url;
}, 1000);
}
layer.msg(info.msg);
}
});
layer.close(index);
}
});
return false;
});
/**
* 清除缓存
*/
$('#clear-cache').on('click', function () {
var _url = $(this).data('url');
if (_url !== 'undefined') {
$.ajax({
url: _url,
success: function (data) {
if (data.code === 1) {
setTimeout(function () {
location.href = location.pathname;
}, 1000);
}
layer.msg(data.msg);
}
});
}
return false;
});