zhuguifei
2026-03-10 58402bd5e762361363a0f7d7907153c77dbb819f
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <title>资源管理</title>
    <jsp:include page="../../../initlib/initAll.jsp"></jsp:include>
    <script type="text/javascript">
        var treeGrid;
        var dialog;
        $(function () {
            treeGrid = $('#treeGrid').treegrid({
                idField: 'id',
                treeField: 'text',
                dataPlain: true,
                fit: true,
                striped: true,
                fitColumns: false,
                rownumbers: true,
                border: false,
                remoteSort: false,
                frozenColumns: [[{
                    title: '编号',
                    field: 'id',
                    width: 150,
                    hidden: true
                }]],
                columns: [[{
                    field: 'text',
                    title: '资源名称',
                    width: 200, editor: "text"
                }, {
                    field: 'url',
                    title: '资源路径',
                    width: 280, editor: "text"
                }, {
                    field: 'typ',
                    title: '资源类型',
                    width: 60,
                    align: 'center',
                    formatter: function (value, row, index) {
                        return value == "1" ? "<span style='color:blue;'>菜单<span>" : "功能";
                    }
                }
                    , {
                        field: 'remark',
                        title: '描述',
                        width: 250, editor: "text"
                    }
                    , {
                        field: 'seq',
                        title: '排序',
                        width: 40, editor: "text",
                        sortable: true
                    }, {
                        field: 'securityLevel',
                        title: '安全级别',
                        width: 60,
                        align: 'center', editor: "text",
                        sortable: true
                    }, {
                        field: 'enable',
                        title: '状态',
                        width: 40,
                        align: 'center',
                        formatter: function (value, row, index) {
                            return value == 1 ? '<span style="color:green;background-color:white">启用<span>' : '<span style="color:red">禁用<span>';
                        }
                    }, {
                        field: 'pname',
                        title: '上级资源',
                        width: 80
                    }, {
                        field: 'createUserName',
                        title: '创建人姓名',
                        align: 'center',
                        width: 70,
                        sortable: true,
                        hidden: 'true'
                    }, {
                        field: 'createUserTime',
                        title: '创建时间',
                        align: 'center',
                        width: 150,
                        sortable: true,
                        hidden: 'true'
                    }, {
                        field: 'updateUserName',
                        title: '修改人姓名',
                        align: 'center',
                        width: 70,
                        sortable: true
                    }, {
                        field: 'updateUserTime',
                        title: '最后修改时间',
                        align: 'center',
                        width: 130,
                        sortable: true
                    }]],
                toolbar: '#toolbar',
                url: "${pageContext.request.contextPath}/pms/sysRes/getAllResources.do",
                onContextMenu: function (e, row) {
                    e.preventDefault();
                    $(this).treegrid('unselectAll');
                    $(this).treegrid('select', row.id);
                    $('#menu').menu('show', {
                        left: e.pageX,
                        top: e.pageY
                    });
                },
                onLoadSuccess: function () {
                    parent.$.messager.progress('close');
 
                    $(this).treegrid('tooltip');
                },
                enableHeaderClickMenu: false,
                enableHeaderContextMenu: false,
                enableRowContextMenu: false,
                autoFocusField: "url",
                autoEditing: true,          //该属性启用双击行时自定开启该行的编辑状态
                extEditing: true,           //该属性启用行编辑状态的 ExtEditing 风格效果,该属性默认为 true。
                singleEditing: true,         //该属性启用datagrid的只允许单行编辑效果,该属性默认为 true。
                onAfterEdit: function (data) {
                    $.fn.treegrid.extensions.onAfterEdit.apply(this, arguments);  //这句一定要加上
                    $.post("${pageContext.request.contextPath}/pms/sysRes/editResource.do",
                        {
                            id: data.id,
                            seq: data.seq,
                            text: data.text,
                            url: data.url,
                            remark: data.remark
                        },
                        function (json) {
                            if (json.success) {
                                //$.messager.show('提示', json.msg, 'info');
                                getAllResources();
                            } else {
                                $.messager.show('提示', json.msg, 'error');
                            }
                        }, "JSON");
                },
                onCancelEdit: function () {
                    //
                }
            });
        });
 
        function redo() {
            var node = treeGrid.treegrid('getSelected');
            if (node) {
                treeGrid.treegrid('expandAll', node.id);
            } else {
                treeGrid.treegrid('expandAll');
            }
        }
 
        function undo() {
            var node = treeGrid.treegrid('getSelected');
            if (node) {
                treeGrid.treegrid('collapseAll', node.id);
            } else {
                treeGrid.treegrid('collapseAll');
            }
        }
 
        function getAllResources() {
            treeGrid.treegrid({url: "${pageContext.request.contextPath}/pms/sysRes/getAllResources.do"});
        }
 
        function goToResourceAddJsp(b) {
            //按钮是否点击标志(默认为true:可被点击)
            var isClick = true;
            var dialog = parent.$.modalDialog({
                title: '资源添加',
                width: 620,
                height: 390,
                href: '${pageContext.request.contextPath}/pms/sysRes/goToResourceAddJsp.do',
                buttons: [{
                    text: '保存',
                    iconCls: 'icon-standard-disk',
                    handler: function () {
                        var f = dialog.find("#form");
                        if (f.form("validate")) {
                            //未点击过则执行里面的内容
                            if (isClick) {
                                //改变为点击无效状态
                                isClick = false;
                                $.post("${pageContext.request.contextPath}/pms/sysRes/addResource.do", f.form("getData"), function (json) {
                                    //恢复点击有效状态
                                    isClick = true;
                                    if (json.success) {
                                        $.messager.show('提示', json.msg, 'info');
                                        dialog.dialog('destroy');
                                        getAllResources();
                                    } else {
                                        $.messager.show('提示', json.msg, 'error');
                                    }
                                }, "JSON");
                            }
                        }
                    }
                }],
                onLoad: function () {
                    if (b) {
                        var row = treeGrid.datagrid('getSelected');
                        dialog.find("#pidComboTree").combotree({value: row.typ == 2 ? row.pid : row.id});
                    }
                }
 
            });
        }
 
        function goToResourceEditJsp() {
            //按钮是否点击标志(默认为true:可被点击)
            var isClick = true;
            var dialog = parent.$.modalDialog({
                title: '资源编辑',
                width: 620,
                height: 390,
                href: '${pageContext.request.contextPath}/pms/sysRes/goToResourceEditJsp.do?id=' + treeGrid.datagrid('getSelected').id,
                buttons: [{
                    text: '保存',
                    iconCls: 'icon-standard-disk',
                    handler: function () {
                        var f = dialog.find("#form");
                        if (f.form("validate")) {
                            //未点击过则执行里面的内容
                            if (isClick) {
                                //改变为点击无效状态
                                isClick = false;
                                $.post("${pageContext.request.contextPath}/pms/sysRes/editResource.do", f.form("getData"), function (json) {
                                    //恢复点击有效状态
                                    isClick = true;
                                    if (json.success) {
                                        $.messager.show('提示', json.msg, 'info');
                                        dialog.dialog('destroy');
                                        getAllResources();
                                    } else {
                                        $.messager.show('提示', json.msg, 'error');
                                    }
                                }, "JSON");
                            }
                        }
                    }
                }]
            });
        }
 
        function deleteResource() {
            //按钮是否点击标志(默认为true:可被点击)
            var isClick = true;
            var row = treeGrid.datagrid('getSelected');
            parent.$.messager.confirm('操作提示', '您是否要删除当前资源?', function (b) {
                if (b) {
                    //未点击过则执行里面的内容
                    if (isClick) {
                        //改变为点击无效状态
                        isClick = false;
                        $.post('${pageContext.request.contextPath}/pms/sysRes/deleteResource.do', {
                            id: row.id,
                            name: row.name
                        }, function (json) {
                            //恢复点击有效状态
                            isClick = true;
                            if (json.success) {
                                $.messager.show('提示', json.msg, 'info');
                                getAllResources();
                            } else {
                                $.messager.show('提示', json.msg, 'error');
                            }
                        }, 'JSON');
                    }
                }
            });
        }
    </script>
</head>
<body>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center',border:false" title="" style="overflow: hidden;">
        <table id="treeGrid"></table>
    </div>
</div>
<div id="toolbar" style="display: none;">
    <table style="margin:4px 0px 0px 0px">
        <tr>
        <%--    <c:if test="${not empty sessionInfo.resourcesMap['/pms/sysRes/getAllResources.do']}">
                <td><a onclick="getAllResources();" href="javascript:void(0);" class="easyui-linkbutton"
                       data-options="plain:true,iconCls:'icon-standard-zoom'">查询</a></td>
            </c:if>--%>
            <c:if test="${not empty sessionInfo.resourcesMap['/pms/sysRes/addResource.do']}">
                <td><a onclick="goToResourceAddJsp();" href="javascript:void(0);" class="easyui-linkbutton"
                       data-options="plain:true,iconCls:'icon-standard-plugin-add'">添加</a></td>
            </c:if>
            <td><a onclick="redo();" href="javascript:void(0);" class="easyui-linkbutton"
                   data-options="plain:true,iconCls:'icon-standard-arrow-out'">展开</a></td>
            <td><a onclick="undo();" href="javascript:void(0);" class="easyui-linkbutton"
                   data-options="plain:true,iconCls:'icon-standard-arrow-in'">折叠</a></td>
        </tr>
    </table>
</div>
 
<div id="menu" class="easyui-menu" style="width: 120px; display: none;">
    <c:if test="${not empty sessionInfo.resourcesMap['/pms/sysRes/addResource.do']}">
        <div onclick="goToResourceAddJsp(true);" data-options="iconCls:'icon-standard-plugin-add'">增加</div>
    </c:if>
    <c:if test="${not empty sessionInfo.resourcesMap['/pms/sysRes/editResource.do']}">
        <div onclick="goToResourceEditJsp();" data-options="iconCls:'icon-standard-plugin-edit'">编辑</div>
    </c:if>
    <c:if test="${not empty sessionInfo.resourcesMap['/pms/sysRes/deleteResource.do']}">
        <div onclick="deleteResource();" data-options="iconCls:'icon-standard-plugin-delete'">删除</div>
    </c:if>
</div>
</body>
</html>