fix: bug#16179

This commit is contained in:
XieYongHong 2023-07-15 19:46:41 +08:00
parent 1b8168786e
commit 6093e544b9
2 changed files with 47 additions and 1 deletions

View File

@ -48,6 +48,7 @@
</template>
<!-- 表格内容 -->
<template #bodyCell="{ column, record }">
<div :id="record.id"></div>
<div v-if="column.key === 'menu'">
<j-checkbox
v-model:checked="record.granted"
@ -110,6 +111,7 @@ import {
USER_CENTER_MENU_CODE
} from '@/utils/consts'
import { isNoCommunity } from '@/utils/utils'
import {useIndirectMenusMap} from "@/views/system/Role/Detail/components/util";
const emits = defineEmits(['update:selectItems']);
const route = useRoute();
@ -270,6 +272,8 @@ const init = () => {
};
init();
const { PermissionsMap } = useIndirectMenusMap(tableData)
function getAllPermiss() {
const id = route.params.id as string;
getPrimissTree_api(id).then((resp) => {
@ -297,6 +301,16 @@ function getAllPermiss() {
}
});
}
const hasIndirectMenus = (data: any) => {
if (data.children) {
const has = data.children.find(item => item.indirectMenus)
console.log(has)
} else if (data?.indirectMenus) {
console.log(data.indirectMenus)
}
}
/**
* 菜单权限改变事件
* @param row 触发的项
@ -306,7 +320,9 @@ function menuChange(
row: tableItemType,
setButtonBool: boolean = true,
): undefined {
console.log('menuChange', row)
//
hasIndirectMenus(row)
if (setButtonBool) {
if (row.buttons && row.buttons.length > 0)
row.buttons.forEach((button) => {
@ -358,7 +374,7 @@ function menuChange(
}
emits('update:selectItems', selectList); //
treeRef.value.$forceUpdate();
proxy?.$forceUpdate?.();
}
/**

View File

@ -0,0 +1,30 @@
import type {Ref} from "vue";
import {watch} from "vue";
const handlePermissionsMap = (data: any, map: Map<string, any>, parentId: string[] = []) => {
data.forEach((item: any) => {
if (item.children) {
handlePermissionsMap(item.children,map, parentId.concat(item.id) )
} else {
map.set(item.id, {
parentIds: parentId,
name: item.name
})
}
})
}
export const useIndirectMenusMap = (tableData: Ref<any[]>) => {
const PermissionsMap = ref<Map<string, any>>(new Map())
watch(() => tableData.value, () => {
PermissionsMap.value.clear()
if (tableData.value?.length) {
handlePermissionsMap(tableData.value, PermissionsMap.value)
}
}, { immediate: true})
return {
PermissionsMap
}
}