无人机管理后台前端(已迁走)
rain
2025-03-26 eb7c68a2db9fa3911b4eecf05f2423fafd482c77
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
<template>
    <basic-container>
        <avue-crud :option="option" :table-loading="loading" :data="data" ref="crud" v-model="form"
            :permission="permissionList" :before-open="beforeOpen" :before-close="beforeClose" @row-del="rowDel"
            @row-update="rowUpdate" @row-save="rowSave" @search-change="searchChange" @search-reset="searchReset"
            @selection-change="selectionChange" @current-change="currentChange" @size-change="sizeChange"
            @refresh-change="refreshChange" @on-load="onLoad" @tree-load="treeLoad">
            <template #menu-left>
                <el-button type="danger" icon="el-icon-delete" v-if="permission.dept_delete" plain
                    @click="handleDelete">删 除
                </el-button>
            </template>
            <template #menu="scope">
                <el-button type="primary" text icon="el-icon-plus" @click.stop="handleAdd(scope.row, scope.index)"
                    v-if="userInfo.role_name.includes('admin')">新增子项
                </el-button>
            </template>
            <template #deptCategory="{ row }">
                <el-tag>{{ row.deptCategoryName }}</el-tag>
            </template>
        </avue-crud>
    </basic-container>
</template>
 
<script>
    import {
        getLazyList,
        getChildLazyTree,
        remove,
        update,
        add,
        getDept,
        getDeptTree
    } from '@/api/system/dept';
    import {
        mapGetters
    } from 'vuex';
    import website from '@/config/website';
 
    export default {
        data() {
            return {
                form: {},
                selectionList: [],
                query: {},
                loading: true,
                parentId: 0,
                page: {
                    pageSize: 10,
                    currentPage: 1,
                    total: 0,
                },
                option: {
                    lazy: true,
                    tip: false,
                    simplePage: true,
                    searchShow: true,
                    searchMenuSpan: 6,
                    tree: true,
                    border: true,
                    index: true,
                    selection: true,
                    viewBtn: true,
                    menuWidth: 320,
                    dialogClickModal: false,
                    column: [{
                            label: '机构名称',
                            prop: 'deptName',
                            search: true,
                            labelWidth: 120,
                            rules: [{
                                required: true,
                                message: '请输入机构名称',
                                trigger: 'blur',
                            }, ],
                        },
                        // {
                        //   label: '所属租户',
                        //   prop: 'tenantId',
                        //   type: 'tree',
                        //   dicUrl: '/blade-system/tenant/select',
                        //   addDisplay: false,
                        //   editDisplay: false,
                        //   viewDisplay: website.tenantMode,
                        //   span: 24,
                        //   props: {
                        //     label: 'tenantName',
                        //     value: 'tenantId',
                        //   },
                        //   hide: !website.tenantMode,
                        //   search: website.tenantMode,
                        //   rules: [
                        //     {
                        //       required: true,
                        //       message: '请输入所属租户',
                        //       trigger: 'click',
                        //     },
                        //   ],
                        // },
                        {
                            label: '机构全称',
                            prop: 'fullName',
                            search: true,
                            labelWidth: 120,
                            rules: [{
                                required: true,
                                message: '请输入机构全称',
                                trigger: 'blur',
                            }, ],
                        },
                        {
                            label: '上级机构',
                            prop: 'parentId',
                            dicData: [],
                            type: 'tree',
                            hide: true,
                            addDisabled: false,
                            props: {
                                label: 'name',
                                value:'id'
                            },
                            labelWidth: 120,
                            rules: [{
                                required: false,
                                message: '请选择上级机构',
                                trigger: 'click',
                            }, ],
                        },
                        {
                            label: '机构类型',
                            type: 'select',
                            dicUrl: '/blade-system/dict/dictionary?code=org_category',
                            props: {
                                label: 'dictValue',
                                value: 'dictKey',
                            },
                            dataType: 'number',
                            width: 120,
                            labelWidth: 120,
                            prop: 'deptCategory',
                            slot: true,
                            rules: [{
                                required: true,
                                message: '请输入机构类型',
                                trigger: 'blur',
                            }, ],
                        },
                        {
                            label: '机构性质',
                            type: 'select',
                            dicUrl: '/blade-system/dict/dictionary?code=org_nature',
                            props: {
                                label: 'dictValue',
                                value: 'dictKey',
                            },
                            dataType: 'number',
                            width: 120,
                            labelWidth: 120,
                            prop: 'deptNature',
                            slot: true,
                            rules: [{
                                required: true,
                                message: '请输入机构性质',
                                trigger: 'blur',
                            }, ],
                        },
                        {
                            label: '排序',
                            prop: 'sort',
                            type: 'number',
                            align: 'right',
                            labelWidth: 120,
                            width: 80,
                            rules: [{
                                required: true,
                                message: '请输入排序',
                                trigger: 'blur',
                            }, ],
                        },
                        {
                            label: '组织id',
                            prop: 'bingId',
                            type: 'number',
                            align: 'right',
                            labelWidth: 120,
                            addDisplay: false,
                            editDisplay: false,
                            width: 80,
                            rules: [{
                                required: true,
                                message: '请输入组织id',
                                trigger: 'blur',
                            }, ],
                        },
                        {
                            label: '备注',
                            prop: 'remark',
                            labelWidth: 120,
                            rules: [{
                                required: false,
                                message: '请输入备注',
                                trigger: 'blur',
                            }, ],
                            hide: true,
                        },
                    ],
                },
                data: [],
            };
        },
        computed: {
            ...mapGetters(['userInfo', 'permission']),
            permissionList() {
                return {
                    addBtn: this.validData(this.permission.dept_add, false),
                    viewBtn: this.validData(this.permission.dept_view, false),
                    delBtn: this.validData(this.permission.dept_delete, false),
                    editBtn: this.validData(this.permission.dept_edit, false),
                };
            },
            ids() {
                let ids = [];
                this.selectionList.forEach(ele => {
                    ids.push(ele.id);
                });
                return ids.join(',');
            },
        },
        methods: {
            initData() {
                getDeptTree().then(res => {
                    const column = this.findObject(this.option.column, 'parentId');
                    column.dicData = res.data.data;
                });
            },
            handleAdd(row) {
                this.parentId = row.id;
                const column = this.findObject(this.option.column, 'parentId');
                column.value = row.id;
                column.addDisabled = true;
                this.$refs.crud.rowAdd();
            },
            rowSave(row, done, loading) {
                add(row).then(
                    res => {
                        // 获取新增数据的相关字段
                        const data = res.data.data;
                        row.id = data.id;
                        row.deptCategoryName = data.deptCategoryName;
                        row.tenantId = data.tenantId;
                        this.$message({
                            type: 'success',
                            message: '操作成功!',
                        });
                        // 数据回调进行刷新
                        done(row);
                    },
                    error => {
                        window.console.log(error);
                        loading();
                    }
                );
            },
            rowUpdate(row, index, done, loading) {
                update(row).then(
                    () => {
                        this.$message({
                            type: 'success',
                            message: '操作成功!',
                        });
                        // 数据回调进行刷新
                        done(row);
                    },
                    error => {
                        window.console.log(error);
                        loading();
                    }
                );
            },
            rowDel(row, index, done) {
                this.$confirm('确定将选择数据删除?', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning',
                    })
                    .then(() => {
                        return remove(row.id);
                    })
                    .then(() => {
                        this.$message({
                            type: 'success',
                            message: '操作成功!',
                        });
                        // 数据回调进行刷新
                        done(row);
                    });
            },
            handleDelete() {
                if (this.selectionList.length === 0) {
                    this.$message.warning('请选择至少一条数据');
                    return;
                }
                this.$confirm('确定将选择数据删除?', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning',
                    })
                    .then(() => {
                        return remove(this.ids);
                    })
                    .then(() => {
                        // 刷新表格数据并重载
                        this.data = [];
                        this.parentId = 0;
                        this.$refs.crud.refreshTable();
                        this.$refs.crud.toggleSelection();
                        // 表格数据重载
                        this.onLoad(this.page);
                        this.$message({
                            type: 'success',
                            message: '操作成功!',
                        });
                    });
            },
            searchReset() {
                this.query = {};
                this.parentId = 0;
                this.onLoad(this.page);
            },
            searchChange(params, done) {
                this.query = params;
                this.parentId = '';
                this.page.currentPage = 1;
                this.onLoad(this.page, params);
                done();
            },
            selectionChange(list) {
                this.selectionList = list;
            },
            selectionClear() {
                this.selectionList = [];
                this.$refs.crud.toggleSelection();
            },
            beforeOpen(done, type) {
                if (['add', 'edit'].includes(type)) {
                    this.initData();
                }
                if (['edit', 'view'].includes(type)) {
                    getDept(this.form.id).then(res => {
                        this.form = Object.assign(res.data.data, {
                            hasChildren: this.form.hasChildren,
                        });
                    });
                }
                done();
            },
            beforeClose(done) {
                this.parentId = '';
                const column = this.findObject(this.option.column, 'parentId');
                column.value = '';
                column.addDisabled = false;
                done();
            },
            currentChange(currentPage) {
                this.page.currentPage = currentPage;
            },
            sizeChange(pageSize) {
                this.page.pageSize = pageSize;
            },
            refreshChange() {
                this.onLoad(this.page, this.query);
            },
            onLoad(page, params = {}) {
                this.loading = true;
                getLazyList(this.parentId, Object.assign(params, this.query)).then(res => {
                    this.data = res.data.data;
                    this.loading = false;
                    this.selectionClear();
                });
            },
            treeLoad(tree, treeNode, resolve) {
                getChildLazyTree({parentId:tree.id}).then(res => {
                    resolve(res.data.data);
                });
            },
        },
    };
</script>
 
<style></style>