吉安感知网项目-前端
shuishen
2026-02-03 89380e6260a75d1d3b94de687ebcc2f50d50659d
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
<template>
    <el-dialog
        class="command-page-view-dialog"
        v-model="visible"
        title="角色权限配置"
        append-to-body
        :close-on-click-modal="false"
        destroy-on-close
        @closed="handleClosed"
    >
        <el-tabs type="border-card">
            <el-tab-pane label="无人机管控">
                <el-tree
                    class="command-tree"
                    ref="droneControl"
                    :data="menuGrantListDroneControl"
                    show-checkbox
                    node-key="id"
                    :default-checked-keys="droneControlMenuTreeObj"
                    :props="treeProps"
                />
            </el-tab-pane>
            <el-tab-pane label="任务工单">
                <el-tree
                    class="command-tree"
                    ref="workRef"
                    :data="menuGrantListWord"
                    show-checkbox
                    node-key="id"
                    :default-checked-keys="menuTreeObjWork"
                    :props="treeProps"
                />
            </el-tab-pane>
            <el-tab-pane label="移动app">
                <el-tree
                    class="command-tree"
                    ref="treeMenuApp"
                    :data="menuGrantListApp"
                    show-checkbox
                    node-key="id"
                    :default-checked-keys="menuTreeObjApp"
                    :props="treeProps"
                />
            </el-tab-pane>
        </el-tabs>
        <template #footer>
            <el-button color="#2B2B4C" @click="visible = false">取消</el-button>
            <el-button color="#284FE3" type="primary" @click="submit">确定</el-button>
        </template>
    </el-dialog>
</template>
 
<script setup>
import { ref } from 'vue'
import { grant, grantTree, getRole } from '@/api/system/role'
import { saveOperationLog } from '@ztzf/apis'
import { useRoute } from 'vue-router'
 
const visible = ref(false)
const roleId = ref('')
const treeProps = {
    label: 'title',
    value: 'key',
}
const menuGrantListApp = ref([])
const menuGrantListDroneControl = ref([])
const menuGrantListWord = ref([])
const menuTreeObjApp = ref([])
const droneControlMenuTreeObj = ref([])
const menuTreeObjWork = ref([])
 
const treeMenuApp = ref(null)
const workRef = ref(null)
const droneControl = ref(null)
 
const emit = defineEmits(['success'])
const route = useRoute()
 
function resetState() {
    menuGrantListApp.value = []
    menuGrantListDroneControl.value = []
    menuGrantListWord.value = []
    menuTreeObjApp.value = []
    droneControlMenuTreeObj.value = []
    menuTreeObjWork.value = []
}
 
async function loadGrantTree(sysType, setter, keysSetter) {
    const grantRes = await grantTree({ sysType })
    setter.value = grantRes?.data?.data?.menu ?? []
    const roleRes = await getRole(roleId.value)
    keysSetter.value = roleRes?.data?.data?.menu ?? []
}
 
async function open({ roleId: id } = {}) {
    roleId.value = id || ''
    visible.value = true
    resetState()
    await Promise.all([
        loadGrantTree(3, menuGrantListApp, menuTreeObjApp),
        loadGrantTree(5, menuGrantListDroneControl, droneControlMenuTreeObj),
        loadGrantTree(6, menuGrantListWord, menuTreeObjWork),
    ])
}
 
function submit() {
    const menuListApp = treeMenuApp.value?.getCheckedKeys?.() ?? []
    const menuListWebWork = workRef.value?.getCheckedKeys?.() ?? []
    const menuListDroneControl = droneControl.value?.getCheckedKeys?.() ?? []
    grant(
        [roleId.value],
        [...menuListApp, ...menuListDroneControl, ...menuListWebWork],
        [],
        []
    ).then(() => {
        saveOperationLog({
            requestUri: route.path,
            title: `${route.name || '角色管理'}-权限设置`,
            type: 1,
        })
        visible.value = false
        emit('success')
    })
}
 
function handleClosed() {
    resetState()
}
 
defineExpose({ open })
</script>