AStaffDetailPrivilege.vue
4.66 KB
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
<template>
<div class="staff-privilege-container">
<el-row :gutter="20">
<el-col :span="18">
<el-card class="box-card">
<div slot="header" class="flex justify-between">
<span>{{ $t('staffDetailPrivilege.orgs') }}</span>
</div>
<el-row v-for="(item, index) in aStaffDetailPrivilegeInfo.orgs" :key="index" :gutter="20">
<el-col :span="12">{{ $t('staffDetailPrivilege.orgName') }}: {{ item.orgName }}</el-col>
<el-col :span="12">{{ $t('staffDetailPrivilege.relCdName') }}: {{ item.relCdName }}</el-col>
</el-row>
</el-card>
<el-card class="box-card" style="margin-top: 20px;">
<div slot="header" class="flex justify-between">
<span>{{ $t('staffDetailPrivilege.roles') }}</span>
</div>
<div v-for="(item, index) in aStaffDetailPrivilegeInfo.roles" :key="index">
{{ item.roleName }}
<p v-if="item.roleCommunityDtoList && item.roleCommunityDtoList.length > 0">
(
<span v-for="(item1, index1) in item.roleCommunityDtoList" :key="index1">
{{ item1.communityName }}
{{ index1 === item.roleCommunityDtoList.length - 1 ? '' : '、' }}
</span> )
</p>
</div>
</el-card>
</el-col>
<el-col :span="6">
<el-card class="box-card">
<div slot="header" class="flex justify-between">
<span>{{ $t('staffDetailPrivilege.privileges') }}</span>
</div>
<el-tree
:data="treeData"
:props="{ label: 'text', children: 'children' }"
default-expand-all
node-key="id"
/>
</el-card>
</el-col>
</el-row>
</div>
</template>
<script>
import { getStaffPrivileges, getStaffOrgs, getStaffRoles } from '@/api/staff/adminStaffDetailApi'
export default {
name: 'AStaffDetailPrivilege',
data() {
return {
aStaffDetailPrivilegeInfo: {
privileges: [],
orgs: [],
roles: [],
staffId: ''
},
treeData: []
}
},
methods: {
switchTab(data) {
this.aStaffDetailPrivilegeInfo.staffId = data.staffId
this.loadStaffPrivileges()
this.loadStaffOrgs()
this.loadStaffRoles()
},
async loadStaffPrivileges() {
try {
const { data } = await getStaffPrivileges({ staffId: this.aStaffDetailPrivilegeInfo.staffId })
this.aStaffDetailPrivilegeInfo.privileges = data.datas
this.treeData = this.buildTreeData(data.datas)
} catch (error) {
this.$message.error(this.$t('staffDetailPrivilege.fetchPrivilegesError'))
}
},
async loadStaffOrgs() {
try {
const { data } = await getStaffOrgs({ staffId: this.aStaffDetailPrivilegeInfo.staffId, page: 1, row: 1 })
this.aStaffDetailPrivilegeInfo.orgs = data.data
} catch (error) {
this.$message.error(this.$t('staffDetailPrivilege.fetchOrgsError'))
}
},
async loadStaffRoles() {
try {
const { data } = await getStaffRoles({ staffId: this.aStaffDetailPrivilegeInfo.staffId, page: 1, row: 9999 })
this.aStaffDetailPrivilegeInfo.roles = data.data
} catch (error) {
this.$message.error(this.$t('staffDetailPrivilege.fetchRolesError'))
}
},
buildTreeData(privileges) {
const groupMap = new Map()
privileges.forEach(pItem => {
if (!groupMap.has(pItem.gId)) {
groupMap.set(pItem.gId, {
id: `g_${pItem.gId}`,
gId: pItem.gId,
text: pItem.gName,
children: []
})
}
})
const menuMap = new Map()
privileges.forEach(pItem => {
const group = groupMap.get(pItem.gId)
if (!menuMap.has(pItem.mId)) {
menuMap.set(pItem.mId, {
id: `m_${pItem.mId}`,
mId: pItem.mId,
text: pItem.mName,
children: []
})
group.children.push(menuMap.get(pItem.mId))
}
})
privileges.forEach(pItem => {
const menu = menuMap.get(pItem.mId)
menu.children.push({
id: `p_${pItem.pId}`,
pId: pItem.pId,
text: pItem.pName
})
})
return Array.from(groupMap.values())
}
}
}
</script>
<style lang="scss" scoped>
.staff-privilege-container {
padding: 20px;
}
</style>