bklLiudl
2024-07-23 277bbae216debe7e6c04e8cc6ee6e1ba9763e14b
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
var RolePermissonManager = {
    InTable: undefined,
    IntableItems: undefined,
 
    // 绑定菜单Table
    SetTable: function (result) {
        // 设定列s
        var cols = [
            {
                // liudl Edit '<input id="viewRes" type="checkbox" onclick="allCheck()" />' 替换权限放开全选功能
                titleHtml: '权限', name: 'Sel', width: 20, align: 'center', lockWidth: false, sortable: false, renderer: function (data, item, rowIndex) {
 
                    var html = "";
                    if (data == 1) {
                        html += '<input id="cb' + rowIndex + '" type="checkbox" checked="checked" onclick="viewClick(' + rowIndex + ')"/>';
                    }
                    else {
                        html += '<input id="cb' + rowIndex + '" type="checkbox" onclick="viewClick(' + rowIndex + ')"/>';
                    }
 
                    return html;
                }
            },
            {
                title: '菜单编号', name: 'ResNum', width: 120, align: 'center', hidden: false, lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '菜单名称', name: 'ResName', width: 160, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
        ];
        if (RolePermissonManager.InTable == undefined) {
            var ht = masterUI.MMGridHeight();
            RolePermissonManager.InTable = $("#tabInfo").mmGrid({
                cols: cols,
                items: result.Result.List,
                checkCol: false,    // 选择框
                indexCol:true,
                nowrap: true,
                fullWidthRows: true,
                remoteSort: true,
                multiSelect: false,
                height: ht / 2 - 25
            });
        }
        else {
            RolePermissonManager.InTable.load(result.Result.List);
        }
    },
 
    // 刷新Table数据源
    load: function (args) {
        try {
            var opts = this.opts;
            this._hideMessage();
            this._loadCount = this._loadCount + 1;
 
            if ($.isArray(args)) {
                //加载本地数据
                this._loadNative(args);
            } else if (opts.url) {
                this._loadAjax(args);
            } else if (opts.items) {
                this._loadNative(opts.items);
            } else {
                this._loadNative([]);
            }
        } catch (e) {
            this._showLoadError();
            throw e;
        }
    },
 
    // 获取菜单Table当前行信息
    GetSelect: function () {
        var list = [];
        if (RolePermissonManager.InTable != undefined) {
            var rows = RolePermissonManager.InTable.selectedRows();
            if (rows != undefined && rows.length > 0) {
                for (var i = 0; i < rows.length; i++) {
                    list.push(rows[i].ResNum);
                }
            }
        }
        return list;
    },
 
    // 获取菜单信息
    PageClick: function (PageIndex, PageSize, parentNum)
    {
        var resNum = $("#Resnum").html();
        $.jBox.tip("正在努力加载数据...", "loading");
        var param = {};
        param["RoleName"] = parentNum;
        param["RoleNum"] = resNum;
        param["PageIndex"] = PageIndex;
        param["PageSize"] = PageSize;
 
        var data = JSON.stringify(param);
        $.gitAjax({
            url: "/SystemSet/RoleAjax/GetResNumMenu",
            data: { ajaxdata: data },
            type: "post",
            dataType: "json",
            success: function (result) {            // result = 后台返回值
                $.jBox.closeTip();
                RolePermissonManager.SetTable(result);
                RolePermissonManager.BindBtnItems('NULL', 'NULL');
            }
        });
    },
 
    // 绑定菜单Table
    SetBtnTable: function (result) {
        // 设定列 &nbsp
        var cols = [
            {
                title: '权限', name: 'Sel', width: 20, align: 'center', lockWidth: false, sortable: false, renderer: function (data, item, rowIndex) {
                   
                    var html = "";
                    if (data == 1) {
                        html += '<input type="checkbox" checked="checked" onclick="danji('+rowIndex+')"/>';
                    }
                    else {
                        html += '<input type="checkbox" onclick="danji(' + rowIndex +')"/>';
                    }
 
                    return html;
                }
            },
            {
                title: '角色编号', name: 'RoleNum', width: 80, align: 'center', hidden: true, lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '功能编号', name: 'ResNum', width: 120, align: 'center', hidden: false, lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '功能名称', name: 'ResName', width: 160, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            //{
            //    title: '角色Id', name: 'Guid', width: 160, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) {
            //        return data;
            //    }
            //},
        ];
        if (RolePermissonManager.IntableItems == undefined) {
            var ht = masterUI.MMGridHeight();
            RolePermissonManager.IntableItems = $("#tabInfoItem").mmGrid({
                cols: cols,
                items: result.Result.List,
                checkCol: false,    // 选择框
                indexCol: true,
                nowrap: true,
                fullWidthRows: true,
                remoteSort: true,
                multiSelect: false,
                height: ht / 2 - 30
            });
        }
        else {
            RolePermissonManager.IntableItems.load(result.Result.List);
        }
 
    },
 
    // 设定按钮权限
    CheckBoxClick: function (rowIndex)
    {
        var list = [];
        if (RolePermissonManager.IntableItems != undefined) {
            var row = RolePermissonManager.IntableItems.row(rowIndex);
            var parentRow = RolePermissonManager.InTable.selectedRows();
            list.push(row.RoleNum);
            list.push(row.ResNum);
            list.push(row.Sel);
            list.push(parentRow[0].ResNum);
            list.push(row.Guid);
        }
 
        if (list.length > 0) {
            var param = {};
            param["RoleNum"] = list[0];
            param["ResNum"] = list[1];
            param["Sel"] = list[2];
            param["ParentNum"] = list[3];
            param["Guid"] = list[4];
            var data = JSON.stringify(param);
            $.gitAjax({
                url: "/SystemSet/RoleAjax/SetRoleRelation",
                data: { ajaxdata: data },
                type: "post",
                dataType: "json",
                success: function (result) {            // result = 后台返回值
                    RolePermissonManager.SetCheckBox(rowIndex, list[2]);
                    RolePermissonManager.SetBtnTable(result);
                }
            });
        }
    },
 
    // 设定菜单权限
    CheckBoxRsMenuClick: function (rowIndex)
    {
        var row = RolePermissonManager.InTable.row(rowIndex);
 
        var param = {};
        param["RoleNum"] = $("#Resnum").html();
        param["ResNum"] = row.ResNum;
        param["Sel"] = row.Sel;
        param["ParentNum"] = $("#parentNum").val();
        param["Guid"] = $("#Resguid").html();
        var data = JSON.stringify(param);
        $.gitAjax({
            url: "/SystemSet/RoleAjax/SetResMenus",
            data: { ajaxdata: data },
            type: "post",
            dataType: "json",
            success: function (result) {            // result = 后台返回值
                // 刷新按钮权限
                RolePermissonManager.InTable.select(rowIndex);
                
                var param1 = {};
                param["RoleName"] = $("#parentNum").val();
                param["RoleNum"] = $("#Resnum").html();;
                param["PageIndex"] = 0;
                param["PageSize"] = 10;
 
                var data = JSON.stringify(param);
                $.gitAjax({
                    url: "/SystemSet/RoleAjax/GetResNumMenu",
                    data: { ajaxdata: data },
                    type: "post",
                    dataType: "json",
                    success: function (result) {            // result = 后台返回值
                        RolePermissonManager.SetTable(result);
                        RolePermissonManager.InTable.select(rowIndex);
                    }
                });
 
                RolePermissonManager.SetBtnTable(result);  
            }
        });
    },
 
    // 设定功能模块权限
    CheckBoxAllClick: function ()
    {
        var ResNum = $("#parentNum").val();
        var Sel = $("#viewRes").prop('checked');
        var RoleNum = $("#Resnum").html();
        var RoleGuid = $("#Resguid").html();
 
        var param = {};
        if (Sel == true) {
            param["Sel"] = "0";
        } else {
            param["Sel"] = "1";
        }
        param["RoleNum"] = RoleNum;
        param["parentNum"] = ResNum;
        param["Guid"] = RoleGuid;
 
        var data = JSON.stringify(param);
        $.gitAjax({
            url: "/SystemSet/RoleAjax/SetRelation",
            data: { ajaxdata: data },
            type: "post",
            dataType: "json",
            success: function (result) {            // result = 后台返回值
                RolePermissonManager.PageClick(1, 10, ResNum);
            }
        });
 
        RolePermissonManager.BindBtnItems('NULL', 'NULL');
    },
 
    // 根据按钮权限改变Table中视图权限
    SetCheckBox: function(rowIndex,Sel) 
    {
        var IntableRowNum = RolePermissonManager.InTable.selectedRowsIndex();
        var rowNum = RolePermissonManager.IntableItems.rowsLength();
        var bl = false;
        for (var i = 0; i < rowNum;i++)
        {
            if (i == rowIndex) {
                continue;
            }
 
            var row = RolePermissonManager.IntableItems.row(i);
            if (row.Sel == Sel)
            {
                bl = true;
            }
        }
        if (Sel == 1) {
            if (!bl) {
                $("#cb" + IntableRowNum).prop("checked", false);
            }
        }
        else {
            $("#cb" + IntableRowNum).prop("checked", true);
        }
    },
 
    // 加载按钮权限
    BindBtnItems: function (roleName, roleNum, roleGuid)
    {
        var param = {};
        param["RoleName"] = roleName;
        param["RoleNum"] = roleNum;
        param["guid"] = roleGuid;
 
        var data = JSON.stringify(param);
        $.gitAjax({
            url: "/SystemSet/RoleAjax/GetResBtnitems",
            data: { ajaxdata: data },
            type: "post",
            dataType: "json",
            success: function (result) {            // result = 后台返回值
                $.jBox.closeTip();
                RolePermissonManager.SetBtnTable(result);
            }
        });
    },
 
    ToolBar: function () {
        //功能模块下拉框值改变触发
        $("#parentNum").change(function () {
            $("#viewRes").prop("checked", false);
            var parentNum = ($(this).val());     
            RolePermissonManager.PageClick(1, 10, parentNum);
        });
 
        // 选择页面加载功能按钮
        $("#tabInfo").click(function () {
            var list = RolePermissonManager.GetSelect();
            if (list.length > 0) {
                var roleName = list[0];
                var roleNum = $("#Resnum").html();
                var roleGuid = $("#Resguid").html();
                RolePermissonManager.BindBtnItems(roleName, roleNum, roleGuid);
            }
        });
    }
}