fix: 菜单tree修复

This commit is contained in:
2024-11-27 15:49:02 +08:00
parent 5b382a124a
commit a607cfed56
4 changed files with 18 additions and 27 deletions

View File

@@ -38,7 +38,7 @@ export default function FormComponent(props: Props) {
const {data} = await getMenu();
const mergeMenu = [
{
id: 0,
id: null,
name: '无父级'
},
...data
@@ -73,7 +73,7 @@ export default function FormComponent(props: Props) {
<Form.Item hidden field="id">
<Input/>
</Form.Item>
<Form.Item label="父级菜单" field="parentId" rules={[{required: true}]}>
<Form.Item label="父级菜单" field="parentId">
<Select
placeholder="请选择父级菜单"
allowClear

View File

@@ -12,21 +12,17 @@ export type IRoute = AuthParams & {
icon?: string
};
const generatorMenu = (data, parentId?:string) => {
const generatorMenu = (data, parentId = '-') => {
const menu = [];
for (const item of data) {
item.key = item.url;
if(!parentId){
menu.push(item);
}else{
if (item.parentId === parentId) {
const children = generatorMenu(data, item.id);
if (children.length) {
item.children = children;
}
menu.push(item);
}
}
if ((item.parentId || '-') === parentId) {
const children = generatorMenu(data, item.id);
if (children.length) {
item.children = children;
}
menu.push(item);
}
}
return menu;
};