Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

编辑菜单时,子菜单和按钮的上级菜单不能选择自身及其子级 #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/utils/tree.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export function filterTree<T extends { children: T[] | undefined }>(tree: T[], iterate: (item: T, index: number) => boolean): T[] {
function filter(tree: T[]): T[] {
return tree.filter((item, index) => {
if (!iterate(item, index)) {
return false;
}
if (item.children && item.children.length > 0) {
item.children = filter(item.children);
}
return true;
})
}
return filter(tree);
}
13 changes: 11 additions & 2 deletions src/views/system/menu/MenuDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import {BasicDrawer, useDrawerInner} from '/@/components/Drawer';
import {list, saveOrUpdateMenu} from './menu.api';
import { useAdapt } from '/@/hooks/system/useAutoAdapt.ts';
import { filterTree } from '/@/utils/tree';

// 声明Emits
const emit = defineEmits(['success', 'register']);
const {width}= useAdapt();
Expand All @@ -36,8 +38,15 @@
isUpdate.value = !!data?.isUpdate;
menuType.value = data?.record?.menuType;

//获取下拉树信息
const treeData = await list();
// 获取当前 record 的 id
const currentId = data?.record?.id;

//获取下拉树信息
let treeData = await list();
if (currentId) {
treeData = filterTree(treeData, (item: any) => item.id !== currentId);
}

updateSchema([{
field: 'parentId',
componentProps: {treeData},
Expand Down