refactor(ideContainer): 优化菜单选中逻辑和 tabs 关闭逻辑

- 修改菜单选中逻辑:使用 parentKey 或 key 设置 currentKey,确保正确同步选中状态
- 注释掉 tabs 关闭时重置 selected 状态的代码,避免不必要的状态变化
- 在侧边栏中添加 selectedKeys,确保树节点选中状态与菜单同步
- 使用 useEffect 在 selectedKey 变化时更新主菜单选中状态
master
钟良源 5 months ago
parent c72382140a
commit b84e15f1cf

@ -161,7 +161,7 @@ function IDEContainer() {
if (menuItem) { if (menuItem) {
setSelected({ setSelected({
currentPath: menuItem.path, currentPath: menuItem.path,
currentKey: menuItem.key currentKey: menuItem.parentKey || menuItem.key
}); });
} }
} }
@ -179,9 +179,9 @@ function IDEContainer() {
setOpenedTabs(newOpenedTabs); setOpenedTabs(newOpenedTabs);
// 如果关闭的是当前激活的tab则重置selected状态 // 如果关闭的是当前激活的tab则重置selected状态
if (path === selected.currentPath) { // if (path === selected.currentPath) {
setSelected({}); // setSelected({});
} // }
}; };
return ( return (

@ -95,6 +95,9 @@ const SideBar: React.FC<SideBarProps> = ({ onMenuSelect, selectedKey, identity }
return null; return null;
}; };
useEffect(() => {
setMainMenuSelectedKey(selectedKey);
}, [selectedKey]);
useEffect(() => { useEffect(() => {
setMenu(getMenuData()); setMenu(getMenuData());
@ -140,6 +143,7 @@ const SideBar: React.FC<SideBarProps> = ({ onMenuSelect, selectedKey, identity }
}}> }}>
<Tree <Tree
defaultExpandedKeys={['0-0']} defaultExpandedKeys={['0-0']}
selectedKeys={[selectedKey || '']} // 添加selectedKeys确保树节点选中状态同步
onSelect={(_selectedKeys, info) => { onSelect={(_selectedKeys, info) => {
const selectedNode = info.node; const selectedNode = info.node;
const originalData = selectedNode.props.dataRef; const originalData = selectedNode.props.dataRef;

Loading…
Cancel
Save