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

master
钟良源 4 months ago
parent 996310d2fe
commit 6982101e5b

@ -183,9 +183,13 @@ 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 来构建子菜单数据结构
Object.keys(newSubMenuData).forEach(subMenuKey => {
const subMenuValue: any = _.cloneDeep(newSubMenuData[subMenuKey]);
const menuIndex = menuData.findIndex(v => v.key === subMenuKey); const menuIndex = menuData.findIndex(v => v.key === subMenuKey);
if (menuIndex !== -1) {
// 构建数据结构,这是目录默认需要的数据结构 // 构建数据结构,这是目录默认需要的数据结构
subMenuValue.forEach(v => { subMenuValue.forEach(v => {
v.title = v.name; v.title = v.name;
@ -193,6 +197,7 @@ const SideBar: React.FC<SideBarProps> = ({
v.path = 'compFlow'; v.path = 'compFlow';
v.parentKey = subMenuKey; v.parentKey = subMenuKey;
v.icon = '/ideContainer/icon/app.png'; v.icon = '/ideContainer/icon/app.png';
if (subMenuKey !== 'appFlow') {
v.children = [ v.children = [
{ {
title: '事件', title: '事件',
@ -205,8 +210,12 @@ const SideBar: React.FC<SideBarProps> = ({
icon: '/ideContainer/icon/list.png' 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;
if (selected?.parentKey === 'appList') {
await getProjectEnvData(originalData); 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