feat(ideContainer):优化侧边栏菜单结构与数据处理逻辑,增加对 appFlow 类型节点的特殊处理

production
钟良源 7 months ago
parent 996310d2fe
commit 6982101e5b

@ -183,30 +183,39 @@ const SideBar: React.FC<SideBarProps> = ({
case 'scene': case 'scene':
const menuData = _.cloneDeep(menuData1); const menuData = _.cloneDeep(menuData1);
const newSubMenuData = _.cloneDeep(subMenuData); const newSubMenuData = _.cloneDeep(subMenuData);
const subMenuKey = Object.keys(newSubMenuData)[0];
const subMenuValue: any = Object.values(newSubMenuData)[0]; // 遍历所有 subMenuKey 来构建子菜单数据结构
const menuIndex = menuData.findIndex(v => v.key === subMenuKey); Object.keys(newSubMenuData).forEach(subMenuKey => {
// 构建数据结构,这是目录默认需要的数据结构 const subMenuValue: any = _.cloneDeep(newSubMenuData[subMenuKey]);
subMenuValue.forEach(v => { const menuIndex = menuData.findIndex(v => v.key === subMenuKey);
v.title = v.name;
v.key = `compFlow-${v.id}`; if (menuIndex !== -1) {
v.path = 'compFlow'; // 构建数据结构,这是目录默认需要的数据结构
v.parentKey = subMenuKey; subMenuValue.forEach(v => {
v.icon = '/ideContainer/icon/app.png'; v.title = v.name;
v.children = [ v.key = `compFlow-${v.id}`;
{ v.path = 'compFlow';
title: '事件', v.parentKey = subMenuKey;
children: null, v.icon = '/ideContainer/icon/app.png';
icon: '/ideContainer/icon/list.png' if (subMenuKey !== 'appFlow') {
}, v.children = [
{ {
title: '组件列表', title: '事件',
children: null, children: null,
icon: '/ideContainer/icon/list.png' icon: '/ideContainer/icon/list.png'
} },
]; {
title: '组件列表',
children: null,
icon: '/ideContainer/icon/list.png'
}
];
}
});
menuData[menuIndex]['children'] = subMenuValue;
}
}); });
menuData[menuIndex]['children'] = subMenuValue;
dispatch(updateMenuData({ 'scene': menuData })); dispatch(updateMenuData({ 'scene': menuData }));
return menuData; return menuData;
case 'componentDevelopment' : case 'componentDevelopment' :
@ -256,7 +265,6 @@ const SideBar: React.FC<SideBarProps> = ({
const parentKey = menu[activeKey]?.key; const parentKey = menu[activeKey]?.key;
const currentMenu = _.cloneDeep(menuData[identity]); const currentMenu = _.cloneDeep(menuData[identity]);
const index = currentMenu.findIndex(v => v.key === parentKey); const index = currentMenu.findIndex(v => v.key === parentKey);
// const res: any = await getProjectEnv(data.id);
const res: any = await getAppInfoNew(data.id); const res: any = await getAppInfoNew(data.id);
if (res.code === 200) { if (res.code === 200) {
const children = currentMenu[index].children.find(v => v.id === data.id); const children = currentMenu[index].children.find(v => v.id === data.id);
@ -483,13 +491,15 @@ const SideBar: React.FC<SideBarProps> = ({
onSelect={async (_selectedKeys, info) => { onSelect={async (_selectedKeys, info) => {
const selectedNode = info.node; const selectedNode = info.node;
const originalData = selectedNode.props.dataRef; const originalData = selectedNode.props.dataRef;
await getProjectEnvData(originalData); if (selected?.parentKey === 'appList') {
await getProjectEnvData(originalData);
// 调用外部传入的菜单选择处理函数 // 调用外部传入的菜单选择处理函数
originalData.key && onMenuSelect?.({ ...originalData } as Selected); originalData.key && onMenuSelect?.({ ...originalData } as Selected);
}
}} }}
style={{ background: 'transparent' }} // 移除背景色 style={{ background: 'transparent' }} // 移除背景色
renderExtra={renderNodeExtra} renderExtra={selected?.parentKey === 'appList' ? renderNodeExtra : null}
> >
{renderMenuItems(menu[activeKey]?.children)} {renderMenuItems(menu[activeKey]?.children)}
</Tree> </Tree>

Loading…
Cancel
Save