diff --git a/src/pages/componentDevelopment/componentCoding/index.tsx b/src/pages/componentDevelopment/componentCoding/index.tsx index 7309ad9..3354bd5 100644 --- a/src/pages/componentDevelopment/componentCoding/index.tsx +++ b/src/pages/componentDevelopment/componentCoding/index.tsx @@ -7,15 +7,31 @@ const Option = Select.Option; const ComponentCoding = () => { const [serverUrl, setServerUrl] = useState('https://arco.design/vue/component/button'); + const [localProjectPath, setLocalProjectPath] = useState(''); + useEffect(() => { + // 监听导航事件 + const handleNavigateToTab = (event: CustomEvent) => { + if (event.detail.path === 'componentCoding' && event.detail.localProjectPath) { + setLocalProjectPath(event.detail.localProjectPath); + } + }; + + document.addEventListener('navigateToTab', handleNavigateToTab as EventListener); + + return () => { + document.removeEventListener('navigateToTab', handleNavigateToTab as EventListener); + }; + }, []); useEffect(() => { const uri = process.env.NEXT_PUBLIC_DEV_CODE_SERVER_HOST; const codeServerFolderPre = '/app/data'; - const tempData = '/000000/admin_testcode1/master'; - setServerUrl(`${uri}?folder=${codeServerFolderPre}${tempData}`); - - }); + + // 使用传入的localProjectPath或默认值 + const path = localProjectPath || '/000000/admin_testcode1/master'; + setServerUrl(`${uri}?folder=${codeServerFolderPre}${path}`); + }, [localProjectPath]); const componentScreening = () => { // 将数据结构修改为级联结构 diff --git a/src/pages/ideContainer/sideBar.tsx b/src/pages/ideContainer/sideBar.tsx index f53bbc0..5fc022c 100644 --- a/src/pages/ideContainer/sideBar.tsx +++ b/src/pages/ideContainer/sideBar.tsx @@ -585,12 +585,42 @@ const SideBar: React.FC = ({ } }; + // 监听导航到Tab的事件 + const handleNavigateToTab = (event: CustomEvent) => { + const { path } = event.detail; + + // 查找对应的菜单项 + const menuItems = menuData[identity]; + if (!menuItems) return; + + const findMenuItem = (items: any[]): any => { + for (const item of items) { + if (item.path === path) { + return item; + } + if (item.children) { + const found = findMenuItem(item.children); + if (found) return found; + } + } + return null; + }; + + const menuItem = findMenuItem(menuItems); + if (menuItem) { + // 触发菜单选择 + onMenuSelect?.({ ...menuItem }); + } + }; + document.addEventListener('toggleNodeVisibility', handleToggleNodeVisibility as EventListener); + document.addEventListener('navigateToTab', handleNavigateToTab as EventListener); return () => { document.removeEventListener('toggleNodeVisibility', handleToggleNodeVisibility as EventListener); + document.removeEventListener('navigateToTab', handleNavigateToTab as EventListener); }; - }, []); + }, [menuData, identity, onMenuSelect]); // 渲染节点的额外操作按钮 const renderNodeExtra = (node) => {