pref(sideBar): 移除Tree组件中的key避免组件被频繁初始化

master
钟良源 3 months ago
parent 6338511741
commit 78ff1a9dd2

@ -325,23 +325,6 @@ const SideBar: React.FC<SideBarProps> = ({
}
}, [menuData, identity]);
// 当 selected 变化时,检查是否需要更新子菜单数据
useEffect(() => {
if (selected?.parentKey === 'appList' && selected?.id) {
// 检查当前菜单数据是否已加载
const currentMenu = menuData[identity] || [];
const appParent = currentMenu.find(item => item.key === 'appList');
if (appParent && appParent.children) {
const appItem = appParent.children.find((item: any) => item.id === selected.id);
if (appItem) {
// 如果应用项没有子菜单数据或者子菜单数据为空,则获取它
if (!appItem.children || appItem.children.length === 0) {
getProjectEnvData(selected);
}
}
}
}
}, [selected, identity, menuData]);
// 根据搜索值过滤菜单数据
const filteredMenu = useMemo(() => {
@ -451,7 +434,6 @@ const SideBar: React.FC<SideBarProps> = ({
// 渲染子菜单
const renderMenuItems = (menuItems?: MenuItemType[], parentKey = '0') => {
console.log('menuItems sidebar', menuItems);
if (menuItems && menuItems.length) {
return menuItems.map((item, index) => {
const key = `${parentKey}-${index}`;
@ -697,8 +679,6 @@ const SideBar: React.FC<SideBarProps> = ({
}}
style={{ background: 'transparent' }} // 移除背景色
renderExtra={selected?.parentKey === 'appList' ? renderNodeExtra : null}
// 当selected或activeKey变化时强制Tree组件重新渲染
key={`tree-${activeKey}-${selected?.key || 'none'}`}
>
{renderMenuItems(filteredMenu[activeKey]?.children)}
</Tree>

Loading…
Cancel
Save