Ldc
2024-04-07 0652600959e5e3b5796fb6e8da129704ca95347a
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
/**
 * 按钮池
 * @author weidy@2019-11-26
 */
layui.define(['layer','element','form','table','util'],function(exports){
    var Class = function(){
        this.MODELNAME = "platform/securityManage/SmButton";
        this.moduleKey = "SmButton";
        this.id='SmButton';
        this.sourceData={};
        this.columns = [];
        this.backPath =  configData.compatibility?path:configData.frameworkPath;
        this.url={
            dataGrid:'smButtonController/dataGrid',//列表数据和查询
            add:'smButtonController/addSave',
            edit:'smButtonController/editSave',
            deleteUrl:'smButtonController/delete'
        };
        this.buttonIconMap = {
            SEARCH:'layui-icon-refresh-2',
            SENIORSEARCH:'layui-icon-query',
            ADD:'layui-icon-add-1',
            EDIT:'layui-icon-edit',
            DELETE:'layui-icon-delete'
        };
        this.getContent=function(){//返回这个组件的基础html
            var that = this;
            var html = "";
            html = [
                    '<div class="layui-layout-border">',
                        '<div class="layui-center">',
                            that.getToolbarHtml(),
                            '<table id="table_', that.id , '" lay-filter="',that.id , '" style="overflow-x:auto;"></table>',//主列表
                        '</div>',
                    '</div>'
            ].join("");
            return html;
        };
        this.getToolbarHtml =function(){
            var that = this;
            var html = [
                '<div layui-filter="toolbar_',that.id, '" class="layui-btn-container">',//主列表的按钮
                '</div>'
            ].join("");
            return html;
        };
        this.getDetailToolbarHtml = function(){
            var me = this;
            return '<div layui-filter="detail_toolbar_' + me.id + '" class="layui-btn-container"></div>';
        };
        this.init=function(){//基础的html被添加后,再执行初始化
            var that = this;
            $webUtil.copyConfig(that,that.moduleKey);
            $webUtil.createButtonHtmlEx(that.sourceData,that.buttonIconMap,$('[layui-filter="toolbar_' + that.id + '"]'),that.id,
                [{uniqueFlag:'ADD',alias:'添加'},{uniqueFlag:'EDIT',alias:'修改'},{uniqueFlag:'DEL',alias:'删除'},{uniqueFlag:'LISTUSED',alias:'查看应用范围'},{uniqueFlag:'CASCADEDEL',alias:'关联删除'},{uniqueFlag:'refresh',alias:'刷新'}],
                [],function(buttons,hasViewRight,hasQueryRight) {
                    hasViewRight = true;
                    hasQueryRight = true;
                    if (hasViewRight) {
                        $webUtil.bindDefultButtonLisenter(that, that.id);
                        var table = layui.table;
                        that.checkColumns();//主列表中列。
                        table.render({
                            elem: '#table_' + that.id,
                            id: 'table_' + that.id,
                            url: that.backPath + that.url.dataGrid,
                            page: {
                                limit: 30,
                                page: 1
                            },
                            cols: [that.columns],
                            done: function (res, cur, count) {
                                if(res && res.data && res.data.length>0){
                                    table.selectRecord('table_' + that.id,res.data[0]);
                                }
                            },
                            rowClick: function (thisTableFilter, record) {
                                if(that.hasDetailRight) {
                                    table.reload("person_" + that.id, {
                                        where: {
                                            oid: record.oid
                                        }
                                    });
                                }
                            }
                        });
                        if(hasQueryRight) {
                            $webUtil.createSearchHtml({
                                id: '按钮标识',
                                name: '按钮名称'
                            }, $('[layui-filter="toolbar_' + that.id + '"]'), 'table_' + that.id);
                        }
                    }else{
                        $webUtil.showErrorMsg("您没有权限浏览本页面");
                    }
            });
        };
        this.ADD = function(){//保存
            var that = this;
            layui.use('form',function(){
                var form = layui.form;
                var filter ="form_" + that.id;
                var addSaveIndex = layer.open({
                    type:1,
                    title:'添加按钮',
                    btn:['保存','取消'],
                    skin:'layui-layer-lan',
                    content:'<form id="form_' + filter + '" lay-filter="' + filter + '" class="layui-form" style="margin-top:5px" ></form>',
                    area:['800px','270px'],
                    closeBtn:2,
                    shade:true,
                    shadeClose:true,
                    resize:true,
                    resizing:function(layero){
                        form.doResize(filter);
                    },
                    success:function(layero) {
                        form.addItems(filter,that.getFormItems(false),
                        function () {}, {}, {defaultColumnOneRow: 2});
                    },
                    yes:function(layero){
                        if(form.validata(filter)){
                            var values = form.getValues(filter);
                            $webUtil.post(that.url.add,values,function(result){
                                if(result.success){
                                    $webUtil.showMsg("添加按钮成功");
                                    layer.close(addSaveIndex);
                                    that.refresh();
                                }else{
                                    $webUtil.showErrorMsg(result.msg);
                                }
                            },function (xhr,error) {
 
                            },that.backPath);
                        }
                    },
                    btn2:function(layero){
                        layer.close(addSaveIndex);
                        that.refresh();
                    }
                });
            });
        };
        this.getFormItems = function(isEdit){
            return [{
                type: 'text',
                name: 'id',
                text: '按钮标识',
                required: true
            }, {
                type: 'text',
                name: 'name',
                text: '按钮名称',
                required: true
            }, {
                name: 'iconCss',
                text: '显示图标'
            }, {
                type: 'text',
                name: 'description',
                text: '描述'
            }];
        };
        this.EDIT = function(){
            var that = this;
            var oid = $webUtil.getOidFromGrid("table_" + that.id,true,true);
            if(!oid){
                return false;
            }
            var selectRowData = layui.table.checkStatus("table_" + that.id);
            layui.use('form',function(){
                var form = layui.form;
                var filter ="form_" + that.id;
                var addSaveIndex = layer.open({
                    type: 1,
                    title: '修改按钮',
                    btn: ['保存', '取消'],
                    url: that.backPath + that.url.edit,
                    skin: 'layui-layer-lan',
                    content: '<form id="form_' + filter + '" lay-filter="' + filter + '" class="layui-form" style="margin-top:5px" ></form>',
                    area: ['800px', '270px'],
                    closeBtn: 2,
                    shade: true,
                    shadeClose: true,
                    resize: true,
                    resizing: function (layero) {
                        form.doResize(filter);
                    },
                    success: function (layero) {
                        form.addItems(filter,that.getFormItems(true),
                            function () {
                                form.setValues(selectRowData.data[0],filter);
                            }
                            , {}
                            , {
                                defaultColumnOneRow: 2
                            });
                    },
                    yes:function(layero){
                        if(form.validata(filter)){
                            var formValues = form.getValues(filter,true);
                            formValues['oid'] = selectRowData.data[0].oid;
                            formValues['ts'] = selectRowData.data[0].ts;
                            $webUtil.put(that.url.edit,formValues,function (result) {
                                if(result.success){
                                    $webUtil.showMsg("修改按钮成功");
                                    that.refresh();
                                    layer.close(addSaveIndex);
                                }else{
                                    $webUtil.showErrorMsg(result.msg);
                                }
                            },function (error) {
 
                            },that.backPath);
                        }
                    },
                    btn2:function(layero){
                        that.refresh();
                        layer.close()
                    }
                });
            });
        };
        
        this.DEL= function(){
            var that = this;
            var oid = $webUtil.getOidFromGrid("table_" +that.id,true,true);
            if(!oid){
                return false;
            }
            var ts =  $webUtil.getOidFromGrid("table_" +that.id,false,false,"ts");
            $webUtil.showConfirmMsg("是否删除这个按钮,对应的功能菜单中的按钮不会自动删除",function () {
                $webUtil.deleteRequest(that.url.deleteUrl,{oid:oid,ts:ts},function(result){
                    if(result.success){
                        $webUtil.showMsg("删除按钮成功");
                        that.refresh();
                    }else{
                        $webUtil.showErrorMsg(result.msg);
                    }
                },function (xhr,error) {
 
                },that.backPath);
            });
        };
        this.checkColumns = function(){
            var that = this;
            var table = layui.table;
            if(that.columns==null || that.columns.length==0){//如果其他地方想使用这个组件的时候,可以自定义列
                that.columns = [table.getIndexColumn(),table.getCheckColumn(),{
                    field:'id',
                    title:'按钮标识',
                    width:150
                },{
                    field:'name',
                    title:'按钮名称',
                    width:200
                },{
                    field:'iconCss',
                    title:'显示图标',
                    width:100
                },{
                    field:'description',
                    title:'描述',
                    width:150
                }];
            }
        };
        this.refresh = function(){
            var that = this;
            layui.table.reload("table_" + that.id);
 
        };
    };
    var cs = new Class();
    exports(cs.MODELNAME,cs);
});