diff --git a/src/pages/ideContainer/index.tsx b/src/pages/ideContainer/index.tsx index df8a70b..ea3324c 100644 --- a/src/pages/ideContainer/index.tsx +++ b/src/pages/ideContainer/index.tsx @@ -6,7 +6,7 @@ import LogBar from './logBar'; import RightSideBar from './rightSideBar'; import NavBar, { NavBarRef } from './navBar'; import { Selected } from '@/pages/ideContainer/types'; -import { updateInfo, updateProjectComponentData } from '@/store/ideContainer'; +import { updateCurrentAppData, updateInfo, updateProjectComponentData } from '@/store/ideContainer'; import { useDispatch, useSelector } from 'react-redux'; import { getAppListBySceneId } from '@/api/apps'; import { getProjectComp } from '@/api/scene'; @@ -200,6 +200,8 @@ function IDEContainer() { const menuItems = menuData[urlParams.identity]; const menuItem = findMenuItem(menuItems, key); + dispatch(updateCurrentAppData({ ...menuItem })); + if (menuItem) { setSelected({ ...menuItem, diff --git a/src/pages/ideContainer/sideBar.tsx b/src/pages/ideContainer/sideBar.tsx index 4b52f32..9851514 100644 --- a/src/pages/ideContainer/sideBar.tsx +++ b/src/pages/ideContainer/sideBar.tsx @@ -17,7 +17,7 @@ import { menuData1, menuData2 } from './config/menuData'; import { IconSearch, IconPlus } from '@arco-design/web-react/icon'; import { Selected } from '@/pages/ideContainer/types'; import { useDispatch, useSelector } from 'react-redux'; -import { updateMenuData, updateFlowData } from '@/store/ideContainer'; +import { updateMenuData, updateFlowData, updateCurrentAppData } from '@/store/ideContainer'; import { addApp, getProjectEnv, editApp, deleteApp } from '@/api/apps'; import _ from 'lodash'; import { getAppInfoNew } from '@/api/appRes'; @@ -281,10 +281,26 @@ const SideBar: React.FC = ({ }; }); + const findMenuItem = (menuItems: any[], key: string): any => { + for (const item of menuItems) { + if (item.key === key) { + return item; + } + if (item.children) { + const found = findMenuItem(item.children, key); + if (found) return found; + } + } + return null; + }; + + // 更新 menuData 中的数据 dispatch(updateMenuData({ ...menuData, [identity]: currentMenu })); // 更新 flowData 中的数据 dispatch(updateFlowData({ [data.id]: res.data })); + // 更新 currentAppData 中的数据 + dispatch(updateCurrentAppData({ ...findMenuItem(menuData[identity], children.key) })); // 同时更新本地 menu 状态以触发重新渲染 setMenu(prevMenu => { diff --git a/src/store/ideContainer.ts b/src/store/ideContainer.ts index ef2cf8c..1bc7502 100644 --- a/src/store/ideContainer.ts +++ b/src/store/ideContainer.ts @@ -6,6 +6,7 @@ interface IDEContainerState { flowData: any; canvasDataMap: any; projectComponentData: any; + currentAppData: any; logBarStatus?: boolean; } @@ -15,6 +16,7 @@ const initialState: IDEContainerState = { flowData: {}, // 编排数据,即流程图的渲染数据 canvasDataMap: {}, // 每个画布的缓存信息 projectComponentData: {}, // 工程下的组件列表 + currentAppData: {}, // 当前选中的应用数据 logBarStatus: false }; @@ -37,6 +39,9 @@ const ideContainerSlice = createSlice({ updateProjectComponentData(state, action) { state.projectComponentData = { ...state.projectComponentData, ...action.payload }; }, + updateCurrentAppData(state, action) { + state.currentAppData = action.payload; + }, updateLogBarStatus(state, action) { state.logBarStatus = action.payload; } @@ -49,6 +54,7 @@ export const { updateFlowData, updateCanvasDataMap, updateProjectComponentData, + updateCurrentAppData, updateLogBarStatus } = ideContainerSlice.actions;