1
lzhe
2024-06-03 a786409d7f6769f43c107159dd84faf4a2927a9a
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
<!--
 * @Author: lzhe lzhe@example.com
 * @Date: 2024-03-26 10:28:33
 * @LastEditors: lzhe lzhe@example.com
 * @LastEditTime: 2024-05-02 22:20:47
 * @FilePath: /smart-web/src/views/master/person/main/index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
    <div class="dict-main">
        <el-form :inline="true" :model="searchData" label-width="80px">
            <el-form-item label="权限名称">
                <el-input v-model="searchData.deptName" placeholder="权限名称" clearable />
            </el-form-item>
            <el-form-item label="权限描述">
                <el-input v-model="searchData.deptName" placeholder="权限描述" clearable></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="searchclick">搜索</el-button>
                <el-button @click="searchClearBtn">清空</el-button>
            </el-form-item>
        </el-form>
        <div>
            <div style="margin-bottom: 12px;">
                <el-button type="primary" @click="addData">添加</el-button>
                <el-button type="danger" @click="delData">删除</el-button>
                <el-button type="primary" @click="addAuthority">权限设置</el-button>
            </div>
            <div class="dict-table">
                <el-table ref="multipleTableRef" :data="tableData" border row-key="id" style="width: 100%" class="multipleTableRef" @selection-change="handleSelectionChange" lazy
      :load="tableLoad" :tree-props="{ children: 'children', hasChildren: 'hasChildren' }" default-expand-all>
                    <el-table-column type="selection" width="55" />
                    <el-table-column prop="deptName" label="权限名称"></el-table-column>
                    <el-table-column prop="fullName" label="权限描述"></el-table-column>
                    <el-table-column prop="deptCategoryName" label="权限类型"></el-table-column>
                    <el-table-column prop="sort" label="排序"></el-table-column>
                    <el-table-column fixed="right" label="操作" width="280">
                        <template #default="scope">
                            <el-button text type="primary" size="small" @click="table_show(scope.row, scope.$index)">查看</el-button>
                            <el-button text type="primary" size="small" @click="table_edit(scope.row, scope.$index)">编辑</el-button>
                            <el-button text type="primary" size="small" @click="table_del(scope.row, scope.$index)">删除</el-button>
                            <el-button text type="primary" size="small" @click="table_edit(scope.row, scope.$index,'fixed')">新增子项</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
        </div>
        <save-dialog v-if="dialog.save" ref="saveDialog" :deptCategoryList="deptCategoryList" :parentIdList ="parentIdList" @success="addDatascopeSuccess" @closed="dialog.save=false"></save-dialog>
 
        <el-dialog title="权限配置" v-model="authorityVisible" :width="800" destroy-on-close>
            <el-tabs type="border-card">
                <el-tab-pane label="数据权限">
                    <el-tree ref="authorityTree" :data="authorityTreeData" :props="{ label: 'title',children: 'children'}" node-key="id" show-checkbox @check-change="treeHandleCheckChange" :default-checked-keys="treeCheck" />
                </el-tab-pane>
            </el-tabs>
        <template #footer>
            <el-button @click="authorityVisible=false" >取 消</el-button>
            <el-button type="primary" :loading="authoritySaveing" @click="authoritySubmit">确定</el-button>
        </template>
    </el-dialog>
    </div>
</template>
<script>
    import saveDialog from './add-scope-manager'
    import * as ElementPlusIconsVue from '@element-plus/icons-vue'
    let icons = []
    for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
        icons.push(key)
    }
    export default {
        name: "datascope",
        data(){
            return {
                treeCheck: [],
                authorityTreeData: [],
                authoritySaveing: false,
                authorityVisible: false,
                scopeTypeNameList: [],
                dialog: {
                    save: false
                },
                drawerTotal: 0,
                direction: "rtl",
                drawer: false,
                icons,
                belongApplicationList: [],
                fileDialogVisible: false,
                getModalData: [],
                selection: [],
                drawerSelection: [],
                total: 0,
                drawerSearchData: {
                    scopeName: "",
                    resourceCode: "",
                    menuId: "",
                    current: 1,
                    size: 10
                },
                searchData: {
                    deptName: "",
                    fullName: "",
                    parentId: "0"
                },
                dialog: {
                    save: false,
                    allocation: false
                },
                tableData: [],
                rowId: "",
                tableRow: {},
                parentIdList: [],
                deptCategoryList: []
            }
        },
        created(){
            
        },
        mounted(){
            this.searchBtn();
            this.getDictionary();
            this.getParentIdList();
        },
        components: {
            ...ElementPlusIconsVue,saveDialog
        },
        methods: {
            treeHandleCheckChange() {
 
            },
            authoritySubmit() {
                var obj = {
                    dataScopeIds: this.$refs.authorityTree.getCheckedKeys(),
                    deptId: this.selectId
                }
                this.authoritySaveing = true;
                this.$HTTP.post("/api/blade-system/data-scope-manager/grant",obj).then(res=> {
                    this.authoritySaveing = false;
                    if(res.code == 200) {
                        this.authorityVisible = false;
                        this.$message.success("操作成功");
                        this.searchClearBtn();
                    }else {
                        this.$alert(res.message, "提示", {type: 'error'});
                    }
                })
            },
            tableLoad(row,treeNode,resolve) {
                this.$HTTP.get(`/api/blade-system/data-scope-manager/lazy-list?parentId=${row.id}`).then(res=> {
                    if(res.code == 200) {
                        resolve(res.data);
                    }
                })
            },
            getParentIdList() {
                this.$HTTP.get("/api/blade-system/data-scope-manager/tree").then(res=> {
                    if(res.code == 200) {
                        this.parentIdList = res.data;
                    }
                })
            },
            getDictionary() {
                this.$HTTP.get("/api/blade-system/dict/dictionary?code=data_scope_category").then(res=> {
                    if(res.code == 200) {
                        this.deptCategoryList = res.data;
                    }
                })
            },
            addDatascopeSuccess() {
                this.searchclick();
            },
            //添加
            addData(){
                this.dialog.save = true;
                this.$nextTick(() => {
                    this.$refs.saveDialog.open(this.parentIdList,this.deptCategoryList);
                })
            },
            getTreeSelect(id) {
                this.$HTTP.get(`/api/blade-system/data-scope-manager/grant-select?deptId=${id}`).then(res=> {
                    if(res.code == 200) {
                        this.treeCheck = res.data;
                    }
                })
            },
            addAuthority() {
                if(this.selection.length != 1) {
                    this.$message({
                        message: '只能选择一条数据',
                        type: 'warning'
                    });
                    return;
                }
                this.selectId = this.selection[0].id;
                this.treeCheck = [];
                this.$HTTP.get("/api/blade-system/menu/grant-tree").then(res=> {
                    if(res.code == 200) {
                        this.authorityTreeData = res.data.dataScope;
                        this.getTreeSelect(this.selectId);
                        this.authorityVisible = true;
                    }
                })
            },
            // 删除
            delData() {
                if(this.selection.length == 0) {
                    this.$message({
                      message: '请选择至少一条数据',
                      type: 'warning'
                    });
                    return;
                }
                var selStr = "";
                this.selection.map(item=> {
                    selStr += item.id + ","
                })
                selStr = selStr.replace(/,$/, '');
                var that = this;
                this.$HTTP.post("/api/blade-system/data-scope-manager/remove?ids="+selStr).then(res=> {
                    if(res.code == 200) {
                        that.$message.success("操作成功");
                        that.searchclick();
                    }
                })
            },
            table_edit(row,index,fixed){  //编辑
                this.dialog.save = true
                this.$nextTick(() => {
                    if(fixed) {  //判断新增子项
                        row.fixed = "fixed";
                    }
                    this.$refs.saveDialog.open(this.parentIdList,this.deptCategoryList,'edit').setData(row)
                })
            },
            //查看
            table_show(row){  //查看
                this.dialog.save = true
                this.$nextTick(() => {
                    this.$refs.saveDialog.open(this.parentIdList,this.deptCategoryList,'show').setData(row)
                })
            },
            table_del(row) {
                var that = this;
                this.$confirm(`确定将选择数据删除?`, '', {
                    type: 'warning'
                }).then(() => {
                    this.$HTTP.post("/api/blade-system/data-scope-manager/remove?ids="+row.id).then(res=> {
                        if(res.code == 200) {
                            that.$message.success("操作成功");
                            that.searchBtn();
                        }
                    })
                }).catch(() => {
 
                })
            },
            exportFile(row,index){
                window.open(row.link);
            },
            codeClick() {
                
            },
            searchClearBtn() {
                this.searchData = {
                    deptName: "",
                    fullName: "",
                    parentId: ""
                }
                this.searchBtn();
            },
            showDrawer(row){
                this.rowId = row.id;
                this.tableRow = row;  //后面组件会用到
                this.drawer = true;
            },
            searchclick() {
                this.searchBtn();
            },
            searchBtn() {
                var obj = {};
                for(var key in this.searchData) {
                    if(this.searchData[key]) {
                        obj[key] = this.searchData[key];
                    }
                }
                this.tableData = [];
                this.$HTTP.get("/api/blade-system/data-scope-manager/lazy-list?" + this.$TOOL.qsStringify(obj)).then(res=> {
                    if(res.code == 200) {
                        this.tableData = res.data;
                    }
                })
            },
            handleSelectionChange(selection) {
                this.selection = selection;
            }
        }
    }
</script>
 
<style scoped>
    .dict-main {
        background-color: #fff;
        margin: 8px;
        padding: 8px;
    }
    .dict-Btn {
        display: flex;
        justify-content: space-between;
        border-bottom: 1px solid #dcdfe6;
        margin-bottom: 8px;
        padding-left: 8px;
        padding-right: 8px;
    }
    .dict-btn-bottom {
        padding-left: 8px;
        padding-right: 8px;
        margin-bottom: 8px;
    }
    .dict-table {
        padding-left: 8px;
        padding-right: 8px;
        margin-bottom: 8px;
        
    }
    .multipleTableRef {
        margin-bottom: 8px;
    }
    .attachSize {
        color:#409eff;
        padding: 0 10px;
        font-size: 12px;
        background-color: #ebf4f4;
        border: 1px solid #d8e8e8;
    }
    /deep/ .drawerStyle {
        padding: 20px;
    }
    .datascope-drawer-btn {
        margin-bottom: 8px;
        padding-left: 8px;
        padding-right: 8px;
    }
</style>