tom
2023-12-06 9e968679ed2e6937aeb7b50a6c450d5d19251f42
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <title>权限管理</title>
        <script src="../../../js/vue/vue.js"></script>
        <script src="../../../js/vue/element-ui/lib/index.js"></script>
        <script src="../../../js/myelement.js"></script>
        <script src="../../../js/vue/page.js"></script>
        <script src="../setting.js"></script>
        
        <link href="../../../js/vue/element-ui/lib/theme-chalk/index.css" rel="stylesheet">
        <link href="../../../css/myelement.css" rel="stylesheet">
        <link href="../../../css/iconfont.css" rel="stylesheet">
        <link href="../../../css/page.css" rel="stylesheet">
        <link href="//at.alicdn.com/t/font_2374495_13ltsxm2eor.css" rel="stylesheet">
    </head>
    
    <body>
        <div id="vbody">
            <div id="page_root">
                <!-- <div class="topbar-line">
                    <div class="query-icon">
                        <i class="iconfont icon-query"></i>
                    </div>
                    <div class="query-bar">
                        <h-form-filter ref="form1"
                            :form-attr="filterAttr" 
                            :table-fields="filterFields" 
                            :form-data="filterObj" 
                            
                            v-on:show-popup="showFilterPopup"
                            v-on:on-query="onQuery"
                            v-on:on-init-query="onInitFilter"
                            v-on:on-edit-query="onEditFilter"
                            >
                        </h-form-filter>
                    </div>
                </div> -->
                
                <div style="width: 100%; height: 100%; padding: 20px; box-sizing: border-box;">
                    
                    <div style="width: 34%; height: 100%; float: left; border: 1px solid #ccc;">
                        
                        <div style="height: 50px; border-bottom: 1px solid #aaa;">
                            <div class="topbar" style="float: left; line-height: 50px;">
                                <span>{{title}}</span>
                            </div>
                            
                            <div style="float: right; margin: 10px;">
                                <el-button-group style="margin-left: 3px;">
                                    <el-button icon="el-icon-refresh" @click="refreshData">刷新</el-button>
                                    <!-- <el-button  v-if="buttons.append" :disabled="buttons.append.disabled" icon="el-icon-plus"  @click="addData">添加</el-button> -->
                                    <el-button v-if="buttons.edit" :disabled="buttons.edit.disabled" @click="setEditTableData">{{isEditTableData ? '取消编辑' : '在线编辑'}}</el-button>
                                </el-button-group>
                            </div>
                        </div>
                        <h-table
                            ref="table1"
                            :table-fields="tableFields" 
                            :table-data="tableData" 
                            :is-edit-table-data="isEditTableData"
                            :pagesize="pagesize"
                            :pagenum="pagenum"
                            :table-height="tableHeight"
                            :is-highlight-row="true"
                            :is-pagination="false"
                            
                            v-on:get-data="getData"
                            v-on:edit-data="editData"
                            v-on:del-data="delData"
                            v-on:row-click="rowClick"
                        >
                        </h-table>
                    </div>
                    <div :style="{width: '65%', height: tableHeight + 60+'px', float: 'right', border: '1px solid #ccc'}">
                        <div v-if="treeData.length > 0" style="height: 50px; border-bottom: 1px solid #aaa;">
                            <div class="topbar" style="float: left; line-height: 50px;">
                                <span>详情</span>
                            </div>
                            <div style="float: right; margin: 10px;">
                                
                                <el-button-group style="margin-left: 3px; ">
                                    <el-button  @click="overloadPermissions()">重载用户权限</el-button>
                                    <el-button icon="el-icon-refresh" @click="">刷新</el-button>
                                    <el-button v-if="isEditTreeData" icon="el-icon-plus"  @click="onNewTreeRecord" >添加</el-button>
                                    <el-button v-if="buttons.edit" :disabled="buttons.edit.disabled" @click="editEnable">{{isEditTreeData ? '保存' : '编辑'}}</el-button>
                                </el-button-group>
                            </div>
                        </div>
                        <div v-if="treeData.length > 0 && istree" :style="{height: tableHeight +'px', padding: '20px', 'box-sizing': 'border-box'}">
                            <div :style="{height: tableHeight - 40  +'px', 'overflow-y': 'auto'}">
                                <el-input
                                  placeholder="输入搜索字"
                                  v-model="filterText">
                                </el-input>
                                <el-tree ref="tree" :data="treeData" :props="defaultProps" node-key="id"  show-checkbox :default-checked-keys="checkMenuList"
                                :filter-node-method="filterNode"  lazy :load="loadNode"
                                highlight-current
                                >
                                <!-- :default-expanded-keys="defaultExpandedKeys"   default-expand-all-->
                                <span class="custom-tree-node" slot-scope="{ node, data }">
                                    <span>{{ node.label }}</span>
                                        <!-- <span v-if="isEditTreeData">
                                            
                                            <el-button style="padding: 2px; font-size: 10px;"
                                            @click="() => editnode(node, data)">编辑</el-button>
                                            <el-button type="danger" size="mini" style="padding: 2px; font-size: 10px;" 
                                            @click="() => remove(node, data)">删除</el-button>
                                        </span> -->
                                    </span>
                                </el-tree>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <div id="page_loading" style="position: absolute; top:0px; width: 100vw; height: 100vh;">
                <div class="spinner">
                  <div class="cube1"></div>
                  <div class="cube2"></div>
                </div>
            </div>
        </div>    
        
        <script type="text/javascript">
            var setting = getSetting("catagory_tree");
            var initlized = false;
            
            new ListVue({
                el: "#vbody",
                data: {
                    dataname: "sysRole",
                    tabaleFieldsName: "hierarchy_tree",
                    //filterFieldsName: "catagory_",
                    datatreename:"hierarchy_tree_mapping",
                    
                    title: "客户类型",
                    page: setting.page,
                    buttons: setting.buttons,
                    tableHeight: 450,
                    isEditTreeData: false,
                    selectTableRow: {},
                    //treeFields: [],
                    
                    istree: false,
                    treeDataObj: {},
                    treeData: [],
                    defaultExpandedKeys: [],
                    defaultProps: {
                        children: 'children',
                        label: 'label',
                    },
                    hierarchy_tree: [],
                    filterText: '',
                    checkMenuList: [],
                },
                created() {
                    this.hierarchy_tree = dataRoot.database.hierarchy_tree;
                },
                
                mounted() {
                    this.initData();
                    this.$nextTick(() => { // 以服务的方式调用的 Loading 需要异步关闭
                        hideLoading();
                    });
                },
                watch: {
                  filterText(val) {
                    this.$refs.tree.filter(val);
                  }
                },
                methods:{
                    initData() {
                        //1. run only
                        if (initlized) { return; }
                        initlized = true;
                                              
                        //2. query data
                        this.onQuery();
                    },
                    onServerInitData(data) {
                        var me = this.data;
                        me.tableFields = data.tableFields;
                        //me.filterFields = data.filterFields;
                        
                        /* if(me.filterFields.length > 0) {
                            for(var i=0; i < me.filterFields.length; i++) {
                                let fieldObj_ = me.filterFields[i];
                                
                                me.filterFieldsObj[fieldObj_.field] = fieldObj_;
                            }
                        }     */
                        if(me.tableFields.length > 0) {
                            for(var i=0; i < me.tableFields.length; i++) {
                                let fieldObj_ = me.tableFields[i];
                                
                                me.tableFieldsObj[fieldObj_.field] = fieldObj_;
                            }
                        }
                    },
                    loadNode(node, resolve) {
                        let me = this;
                        var data_ = [];
                            if (node.level === 0) {
                              this.getTree();
                            }
                            if (node.level > 0) {
                                let param_ = {
                                    isClientMode: false,
                                    roles:me.selectTableRow.id,
                                    filter:"parent_id = '" +node.data.id +"'",
                                    orderby: "orderno"
                                }
                                Server.call("root/data/getEntitySet/resourceMenu", param_, function(result) {
                                    console.log(result);
                                    data_ = result.data.entityset;
                                    let obj = {};
                                    let list = JSON.parse(JSON.stringify(data_));
                                    list.map(el => {
                                        obj[el.id] = el;
                                    })
                                    for (let i = 0, len = list.length; i < len; i++) {
                                        let parentId_ = list[i].parent_id;
                                        //如果存在判断只读字段,并且该字段有值则设置该节点为只读
                                        list[i].disabled = true;
                                        if(list[i].active){
                                            me.checkMenuList.push(list[i].id);
                                        }
                                        //list[i].checked = true;
                                        list[i].label = decodeURI(list[i].text);
                                        list[i].name = decodeURI(list[i].text);
                                    }
                                    resolve(list);
                                    
                                    if(data_.length == 0 && node.data.parent_id){
                                        let param = {
                                            isClientMode: false,
                                            roles:me.selectTableRow.id,
                                            filter:"page_id = '" +node.data.page_id +"'",
                                            //orderby: "orderno"
                                        }
                                    
                                        Server.call("root/data/getEntitySet/resource_button", param, function(result) {
                                            console.log(result);
                                            data_ = result.data.entityset;
                                            let obj = {};
                                            let list = JSON.parse(JSON.stringify(data_));
                                            list.map(el => {
                                                obj[el.id] = el;
                                            })
                                            for (let i = 0, len = list.length; i < len; i++) {
                                                let parentId_ = list[i].parent_id;
                                                if(list[i].active){
                                                    me.checkMenuList.push(list[i].id);
                                                }
                                                //如果存在判断只读字段,并且该字段有值则设置该节点为只读
                                                list[i].disabled = true;
                                                list[i].label = decodeURI(list[i].name);
                                                list[i].name = decodeURI(list[i].name);
                                            }
                                            resolve(list);
                                        
                                        });
                                        /* data_ = result.data.entityset;
                                        for (let i = 0;i < data_.length; i++) {
                                            data_[i].disbaled = false;
                                            //me.treeData[0].children.push(result.data.entityset[i]);
                                        } */
                                    }
                                    
                                
                                })
                            };
                            
                          },
                    
                    onAddData(config) {
                        var me = this;
                        
                        config.combine({
                            url: "../md/plan/hierarchy_tree_edit.html",
                            sceneCode: "add",
                            data: {},
                            delta: {},
                            callback: function(obj) {
                                me.saveRowTable_popup(obj);
                            }
                        });
                        
                        return true;
                    },
                    
                    onEditData(config, scope) {
                        var me = this;
                        var row = scope.row;
                        
                        //1. empty row
                        if (!row || !row.id) {
                            Root.message({
                                type: 'warning',
                                message: '请选择要编辑的数据'
                            });  
                            return false;
                        }
                        
                        //2. popup                    
                        config.combine({
                            url: "../md/plan/hierarchy_tree_edit.html",
                            sceneCode: "edit",
                            data: row,
                            delta: {},
                            callback: function(obj) {
                                me.saveRowTable_popup(obj);
                            }
                        });
                        
                        return true;
                    },
                    
                    rowClick(obj) {
                        this.selectTableRow = obj.row;
                        this.getTree();
                    }, 
                    
                    getTree() {
                        
                        let me = this;
                        let filter_ = "parent_id = ''" ;
                        this.filterList = [];
                        
                        let param_ = {
                            isClientMode: false,
                            
                            filterList: this.filterList,
                            filter: filter_,
                            roles:this.selectTableRow.id,
                            orderby: "orderno",
                        }
                        Server.call("root/data/getEntitySet/resourceMenu", param_, function(result) {
                            console.log(result);
                            me.customertypedetailed = [];
                            if (result && result.data) {
                                var data_ = result.data.entityset;
                                me.customertypedetailed = data_;
                            }
                            me.defaultExpandedKeys = [];
                            me.istree = false;
                            let treeDataList = me.customertypedetailed;
                            treeDataList.map(e=>{
                                me.treeDataObj[e.id] = e;
                            });
                            let treeData_ = me.ArrayToTree(treeDataList, "text", "page_id");
                            treeData_.map(e=>{
                                me.defaultExpandedKeys.push(e.id);
                                if (e.children) {
                                    e.children.map(ec=>{
                                        
                                    });
                                }
                            });
                            this.checkMenuList = [];
                            let param = {
                                isClientMode: false,
                            }
                            /* Server.call("root/data/getEntitySet/resourceMenu", param, function(result) {
                                me.checkMenuList = result.map(one => {
                                    return one.menu_id
                                });
                                me.$refs.tree.setCheckedKeys(me.checkMenuList);
                                
                            }); */
                            
                            
                            
                            for(var i = 0; i < treeData_.length; i++) {
                                var children = treeData_[i].children
                                if (children != undefined) {
                                    for(var g = 0; g< children.length; g++) {
                                        var childrenChild = children[g].children
                                        if(childrenChild != undefined){
                                            for(var h = 0; h < childrenChild.length; h++){
                                                childrenChild[h].disabled = true
                                            }
                                        }
                                        
                                        children[g].disabled = true
                                    }
                                }
                                treeData_[i].disabled = true
                            } 
                            
                            me.treeData = treeData_;
                            me.isEditTreeData = false;
                            me.istree = true;
                        }); 
                    }, 
                    editEnable(){
                        
                        //编辑树
                        let treeDataList = this.treeData;
                        let treeData_ = ArrayToTree(treeDataList, "name", "parentid");
                        this.treeData = treeData_;
                        if(!this.isEditTreeData){
                            this.istree = false;
                            //this.treeFields[1].options = treeData_;
                            for(var i = 0; i < this.treeData.length; i++) {
                                var children = this.treeData[i].children
                                if (children != undefined) {
                                    for(var g = 0; g< children.length; g++) {
                                        var childrenChild = children[g].children
                                        if(childrenChild != undefined){
                                            for(var h = 0; h < childrenChild.length; h++){
                                                childrenChild[h].disabled = false
                                            }
                                        }
                                        
                                        children[g].disabled = false
                                    }
                                }
                                this.treeData[i].disabled = false
                            } 
                            this.istree = true;
                        }
                        //保存树
                        if(this.isEditTreeData){
                            this.istree = false;
                            for(var i = 0; i < this.treeData.length; i++) {
                                var children = this.treeData[i].children
                                if (children != undefined) {
                                    for(var g = 0; g< children.length; g++) {
                                        var childrenChild = children[g].children
                                        if(childrenChild != undefined){
                                            for(var h = 0; h < childrenChild.length; h++){
                                                childrenChild[h].disabled = true
                                            }
                                        }
                                        children[g].disabled = true
                                    }
                                }
                                this.treeData[i].disabled = true
                            } 
                            this.istree = true;
                        }
                        this.isEditTreeData = !this.isEditTreeData;
                    },
                    
                    ArrayToTree(array_, name, parentId, parId, disabled_field, isencode) {
                        if(!parentId) {
                            parentId = "parent_id";
                        }
                        if(!name) {
                            name = "label";
                        }
                        if(!parId) {
                            parId = "";
                        }
                        
                        let obj = {};
                        let result = [];
                        let list = JSON.parse(JSON.stringify(array_));
                        list.map(el => {
                            obj[el.id] = el;
                        })
                        let openId = "";
                        for (let i = 0, len = list.length; i < len; i++) {
                            let parentId_ = list[i][parentId];
                            //如果存在判断只读字段,并且该字段有值则设置该节点为只读
                            if (disabled_field) {
                                if(list[i][disabled_field]) {
                                    list[i].disabled = true;
                                }
                            }
                            
                            //设置显示字段
                            if (isencode) {
                                list[i].label = decodeURI(encodeURI( list[i][name]));//数据如果带“%”的需要编码再解码,否则会存在格式错误
                                list[i].name = decodeURI(encodeURI( list[i][name]));
                            }
                            else {
                                list[i].label = decodeURI(list[i][name]);
                                list[i].name = decodeURI(list[i][name]);
                            }
                            if (parentId_ == parId || !parentId_ || parentId_ == "null") {
                                if(!obj[list[i].id].children) {
                                    obj[list[i].id].children = null;
                                }
                                result.push(list[i]);
                                continue;
                            } else if (obj[parentId_]) {
                                if (!obj[parentId_].children) {
                                    obj[parentId_].children = [];
                                }
                                obj[parentId_].children.push(list[i]);
                            }
                        }
                        return result;
                    },
                    overloadPermissions(){
                        let param = {
                            isClientMode: false,
                        }
                        
                        Server.call("root/tool/delCache/", param, function(result) {
                            console.log(result);
                        }); 
                    },
                    onNewTreeRecord() {
                        
                        //1.
                        this.operationtype = "add";
                        //this.selectedrow = {};
                        
                        //2. get config and go
                        var config = new Config(), go = true;
                        
                        if (this.onAddTreeData) {
                             go = this.onAddTreeData.call(this, config);
                        }
                        
                        //3. popup
                        if (go) {
                            this.doPopup(config);
                        }
                    },
                    onAddTreeData(config) {
                        var me = this;
                        config.combine({
                            url: "../md/customer/catagory_node_edit.html",
                            sceneCode: "add",
                            data: {},
                            delta: {},
                            callback: function(obj) {
                                me.saveRowTree_popup(obj);
                            }
                        });
                        
                        return true;
                    },
                    //编辑树
                    editnode: function(scope) {
                        //1.
                        this.operationtype = "edit";
                        //this.selectedrow = scope.row;
                        
                        //2. get config and go
                        var config = new Config(), go = true;
                        if (this.onEditTreeData) {
                            go = this.onEditTreeData.call(this, config, scope);
                        }
                        
                        //3. popup
                        if (go) {
                            this.doPopup(config);
                        }
                    },
                    onEditTreeData(config, scope) {
                        var me = this;
                        var row = scope.data;
                        
                        //1. empty row
                        if (!row || !row.id) {
                            Root.message({
                                type: 'warning',
                                message: '请选择要编辑的数据'
                            });  
                            return false;
                        }
                        
                        //2. popup                    
                        config.combine({
                            url: "../md/customer/catagory_node_edit.html",
                            sceneCode: "edit",
                            data: row,
                            delta: {},
                            callback: function(obj) {
                                me.saveRowTree_popup(obj);
                            }
                        });
                        
                        return true;
                    },
                    
                    remove(node, data) {
                        let me = this;
                        Root.confirm('确定删除-' + data.name + '-吗?', '删除提示', {
                          confirmButtonText: '删除',
                          cancelButtonText: '取消',
                          type: 'warning'
                        }).then(() => {
                            let param = {
                                id: data.id,
                                isClientMode: false,
                            }
                            Server.call("root/data/deleteEntity/"+ this.datatreename, param, function(result) {
                                console.log(result);
                                Root.message({
                                    type: 'success',
                                    message: '删除成功!'
                                });
                                me.getTree();
                            });
                        }).catch(() => {
                            Root.message({
                                type: 'info',
                                message: '已取消删除'
                            });          
                        });
                    },
                    saveRowTree_popup: function(obj) {
                        var me = this;
                        var formData_ = obj.row;
                        var operationtype_ = this.operationtype;
                        
                        if (operationtype_ == "edit") {//修改
                            var paramObj = {};
                            for (var k in formData_) {
                                paramObj[k] = formData_[k];
                            }
                            var param = paramObj;
                            param.isClientMode = false;
                            
                            Server.call("root/data/updateEntity/" + this.datatreename, param, function(result) {
                                console.log(result);
                                me.getTree();
                            });
                        }
                        
                        else {//新增
                            var param = formData_;
                            param.isClientMode = false;
                            Server.call("root/data/insertEntity/" + this.datatreename, param, function(result) {
                                console.log(result);
                                me.getTree();
                            });
                        }
                    },
                     filterNode(value, data) {
                        if (!value) return true;
                        return data.label.indexOf(value) !== -1;
                    },
                }
            });
        </script>
    </body>
</html>