-
Notifications
You must be signed in to change notification settings - Fork 16
/
menu-list.html
207 lines (194 loc) · 8.09 KB
/
menu-list.html
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
196
197
198
199
200
201
202
203
204
205
206
207
<!DOCTYPE html>
<html>
<#import "common/common-import.html" as netCommon>
<@netCommon.commonImport />
<body>
<div class="layuimini-container">
<div class="layuimini-main">
<fieldset class="table-search-fieldset">
<legend>搜索信息</legend>
<div style="margin: 10px 10px 10px 10px">
<form class="layui-form layui-form-pane" action="">
<div class="layui-form-item">
<div class="layui-form-item">
<label class="layui-form-label required">父菜单</label>
<div id="departmentArea" class="layui-input-block">
<select id="parentMenuId" name="parentMenuId" lay-filter="parentMenuId">
<option value="0">主菜单</option>
</select>
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">菜单名称</label>
<div class="layui-input-inline">
<input type="text" name="title" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-inline">
<button id="searchBtn" type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
</div>
</div>
</form>
</div>
</fieldset>
<script type="text/html" id="toolbarDemo">
<div class="layui-btn-container">
<button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> <i class="layui-icon layui-icon-addition"></i>添加菜单 </button>
</div>
</script>
<table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
<script type="text/html" id="currentTableBar">
<a class="layui-btn layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
</script>
<script type="text/html" id="statusTemplate">
{{# if(d.status = 1){ }}
启用
{{# } else { }}
停用
{{# } }}
</script>
</div>
</div>
<script>
layui.use(['form', 'table'], function () {
var $ = layui.jquery,
form = layui.form,
table = layui.table;
<@netCommon.jwtHandle />
table.render({
elem: '#currentTableId',
method: 'post',
url: '${request.contextPath}/menu/list',
toolbar: '#toolbarDemo',
defaultToolbar: ['filter', 'exports', 'print', {
title: '提示',
layEvent: 'LAYTABLE_TIPS',
icon: 'layui-icon-tips'
}],
cols: [[
{field: 'menuId', title: 'ID', sort: true},
{field: 'title', title: '名称', sort: true},
{field: 'href', title: '链接', sort: true},
{field: 'icon', title: '图标', sort: true},
{field: 'parentMenuId', title: '父菜单ID', sort: true},
{title: '操作', minWidth: 50, templet: '#currentTableBar', fixed: "right", align: "center"}
]],
limits: [20, 50 , 100],
limit: 20,
page: true
});
var result;
// 监听搜索操作
form.on('submit(data-search-btn)', function (data) {
result = JSON.stringify(data.field);
//执行搜索重载
table.reload('currentTableId', {
page: {
curr: 1
}
, where: {
searchParams: result
}
}, 'data');
return false;
});
var searchBtn = $("#searchBtn");
/**
* toolbar监听事件:表格添加按钮
*/
table.on('toolbar(currentTableFilter)', function (obj) {
if (obj.event === 'add') {
var index = layer.open({
title: '添加',
type: 2,
shade: 0.2,
maxmin: true,
shadeClose: true,
area: ['1000px', '700px'],
content: '${request.contextPath}/menu/edit?id=0'+"&token="+layui.data('token').token,
});
return false;
}
});
// 监听删除操作
$(".data-delete-btn").on("click", function () {
var checkStatus = table.checkStatus('currentTableId')
, data = checkStatus.data;
layer.alert(JSON.stringify(data));
});
//监听表格复选框选择
table.on('checkbox(currentTableFilter)', function (obj) {
console.log(obj)
});
/**
* tool监听事件:表格编辑删除等功能按钮
*/
table.on('tool(currentTableFilter)', function (obj) {
var data = obj.data;
if (obj.event === 'edit') {
var index = layer.open({
title: '编辑',
type: 2,
shade: 0.2,
maxmin:true,
shadeClose: true,
area: ['800px', '500px'],
content: '${request.contextPath}/menu/edit?id='+obj.data.menuId+"&token="+layui.data('token').token,
});
return false;
} else if (obj.event === 'delete') {
layer.confirm('真的删除行么', function (index) {
$.ajax({
type: 'POST',
url: "${request.contextPath}/menu/delete",
data:{"id":obj.data.menuId},
success: function (responseData) {
if (responseData.code === 200) {
layer.msg(responseData.msg, function () {
obj.del();
});
} else {
layer.msg(responseData.msg, function () {
//window.location = '/index.html';
});
}
}
});
layer.close(index);
});
}
});
function initMenu(){
$.ajax({
type: 'POST',
url: "${request.contextPath}/menu/list",
data:{"searchParams":"{'parentMenuId':'0'}","page":"1","limit":"99"},
success: function (responseData) {
if (responseData.code === 200 || responseData.code === 0) {
var length = responseData.data.length;
console.log("parentMenuId.length:"+length);
$("#parentMenuId").empty();
$("#parentMenuId").append('<option value="">全部菜单</option>');
$("#parentMenuId").append('<option value="0">主菜单</option>');
for(var i = 0; i < length; i++) {
//添加option元素
$("#parentMenuId").append("<option value='" + responseData.data[i].menuId + "'>" + responseData.data[i].title + "</option>");
}
$("#parentMenuId").val("");
form.render('select');
} else {
layer.msg("加载主菜单列表失败:"+responseData.msg, function () {
//window.location = '/index.html';
});
}
}
});
}
initMenu();
});
</script>
<script>
</script>
</body>
</html>