|
|
@@ -6,7 +6,9 @@
|
|
|
</template>
|
|
|
<template #menuids>
|
|
|
<el-scrollbar max-height="300px" style="width: 100%; border: 1px solid #f2f2f2;">
|
|
|
- <el-tree :data="filteredRoutes" :props="{ label: (data: Model.MenusRsp)=> t('routes.'+data.resourceCode) }" node-key="resourceCode" />
|
|
|
+ <el-tree :data="filteredRoutes"
|
|
|
+ :props="{ label: (data: Model.MenusRsp) => t('routes.' + data.resourceCode) }"
|
|
|
+ node-key="resourceCode" />
|
|
|
</el-scrollbar>
|
|
|
</template>
|
|
|
</app-table-details>
|
|
|
@@ -29,7 +31,7 @@ import AppTableDetails from '@pc/components/base/table-details/index.vue'
|
|
|
|
|
|
const props = defineProps({
|
|
|
record: {
|
|
|
- type: Object as PropType<Member.OrganRoleRsp>,
|
|
|
+ type: Object as PropType<Model.RoleRsp>,
|
|
|
required: true
|
|
|
}
|
|
|
})
|
|
|
@@ -57,16 +59,32 @@ const { data, loading } = useRequest(queryDetail, {
|
|
|
},
|
|
|
onSuccess: (res) => {
|
|
|
const codeSet = new Set(res.data.menuids)
|
|
|
+
|
|
|
+ function filterMenu(data: Model.MenusRsp[]) {
|
|
|
+ return data.reduce<Model.MenusRsp[]>((result, item) => {
|
|
|
+ const { resourceCode, children } = item
|
|
|
+ if (codeSet.has(resourceCode)) {
|
|
|
+ // 当前菜单项符合条件
|
|
|
+ result.push({
|
|
|
+ ...item,
|
|
|
+ children: children ? filterMenu(children) : [],
|
|
|
+ })
|
|
|
+ } else if (children?.length) {
|
|
|
+ // 当前菜单项不符合条件,但有子菜单,递归过滤子菜单
|
|
|
+ const filteredChildren = filterMenu(children)
|
|
|
+ if (filteredChildren.length) {
|
|
|
+ result.push({
|
|
|
+ ...item,
|
|
|
+ children: filteredChildren,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result
|
|
|
+ }, [])
|
|
|
+ }
|
|
|
+
|
|
|
// 递归过滤菜单
|
|
|
- filteredRoutes.value = routerStore.userRoutes.filter(menu => {
|
|
|
- if (codeSet.has(menu.resourceCode)) {
|
|
|
- return true
|
|
|
- }
|
|
|
- if (menu.children && menu.children.length) {
|
|
|
- return menu.children.some(child => codeSet.has(child.resourceCode))
|
|
|
- }
|
|
|
- return false
|
|
|
- })
|
|
|
+ filteredRoutes.value = filterMenu(routerStore.userRoutes)
|
|
|
},
|
|
|
onError: (err) => {
|
|
|
ElMessage.error(err)
|
|
|
@@ -74,9 +92,9 @@ const { data, loading } = useRequest(queryDetail, {
|
|
|
})
|
|
|
|
|
|
const detailProps: CellProp[] = [
|
|
|
- { prop: 'rolename', label: t('admin.role.edit.rolename') },
|
|
|
- { prop: 'sensitivefields', label: t('admin.role.edit.sensitivefields') },
|
|
|
- { prop: 'menuids', label: t('admin.role.edit.menuids') },
|
|
|
+ { prop: 'rolename', label: 'admin.role.edit.rolename' },
|
|
|
+ { prop: 'sensitivefields', label: 'admin.role.edit.sensitivefields' },
|
|
|
+ { prop: 'menuids', label: 'admin.role.edit.menuids' },
|
|
|
]
|
|
|
|
|
|
const onCancel = () => {
|