From e98a344b9507ef3401491b24e05cf93c7dca54e7 Mon Sep 17 00:00:00 2001 From: typist Date: Wed, 29 Oct 2025 08:33:22 +0800 Subject: [PATCH] feat: enhance sidebar component with recursive submenu rendering - Implemented recursive rendering of submenu items in the sidebar for better navigation. - Added support for collapsible submenus, improving user experience with nested tools. - Refactored menu item rendering logic to utilize a new renderSubMenuContent function for cleaner code. --- src/components/sidebar/index.tsx | 69 ++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 21 deletions(-) diff --git a/src/components/sidebar/index.tsx b/src/components/sidebar/index.tsx index 5f6a6a4..5474513 100644 --- a/src/components/sidebar/index.tsx +++ b/src/components/sidebar/index.tsx @@ -13,6 +13,46 @@ export const AppSidebar = () => { return `/tool/${pathSegments.join("/")}`; }; + // 递归渲染子菜单内容 + const renderSubMenuContent = (child: Tool, currentPaths: string[]): ReactNode => { + if (child.children) { + // 子菜单内的可折叠项 + return ( + + + + {child.icon} + {child.name} + + + + + + {child.children.map((subChild) => ( + + {renderSubMenuContent(subChild, [...currentPaths, child.path])} + + ))} + + + + ); + } + + // 叶子节点 + return ( + + + {child.icon} + {child.name} + + + ); + }; + // 递归渲染菜单项 const renderMenuItem = (tool: Tool, parentPaths: string[] = []): ReactNode => { const currentPaths = [...parentPaths, tool.path]; @@ -20,12 +60,11 @@ export const AppSidebar = () => { if (tool.children) { // 有子菜单的项目 return ( - - + + {tool.icon} @@ -37,25 +76,13 @@ export const AppSidebar = () => { {tool.children.map((child) => ( - {child.children ? ( - renderMenuItem(child, currentPaths) - ) : ( - - - {child.icon} - {child.name} - - - )} + {renderSubMenuContent(child, currentPaths)} ))} - - + + ); }