From f46827f869721db05af1683c46fa674d92ec63ea Mon Sep 17 00:00:00 2001 From: ZLY Date: Tue, 4 Nov 2025 15:12:44 +0800 Subject: [PATCH] =?UTF-8?q?feat(ide):=20=E6=B7=BB=E5=8A=A0=E5=B7=A5?= =?UTF-8?q?=E7=A8=8B=E7=BA=A7=E5=85=A8=E5=B1=80=E5=8F=98=E9=87=8F=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/ideContainer/index.tsx | 10 +++++++++- src/pages/orchestration/globalVar/index.tsx | 11 ++++------- src/store/ideContainer.ts | 8 +++++++- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/pages/ideContainer/index.tsx b/src/pages/ideContainer/index.tsx index ac37cb9..466526f 100644 --- a/src/pages/ideContainer/index.tsx +++ b/src/pages/ideContainer/index.tsx @@ -14,7 +14,8 @@ import { updateCurrentAppData, updateInfo, updateProjectComponentData, - updateEventList + updateEventList, + updateGlobalVarList } from '@/store/ideContainer'; import { getAppListBySceneId } from '@/api/apps'; import { getProjectComp } from '@/api/scene'; @@ -32,6 +33,7 @@ import ComponentTest from '@/pages/componentDevelopment/componentTest'; import { getUserToken } from '@/api/user'; import { Message } from '@arco-design/web-react'; import { queryEventItemBySceneId, queryEventItemBySceneIdOld } from '@/api/event'; +import { getGlobalList } from '@/api/global'; type UrlParamsOptions = { identity?: string; @@ -225,6 +227,11 @@ function IDEContainer() { if (res1.code === 200) dispatch(updateEventListOld(res1.data)); }; + const getGlobalVar = async () => { + const res: any = await getGlobalList(urlParams.id); + if (res.code === 200) dispatch(updateGlobalVarList(res.data)); + }; + useEffect(() => { setUrlParams(getUrlParams(window.location.href) as UrlParamsOptions); dispatch(updateInfo(getUrlParams(window.location.href) as UrlParamsOptions)); @@ -241,6 +248,7 @@ function IDEContainer() { if (urlParams.identity && urlParams.identity === 'scene') { connectWS(); getEvent(); + getGlobalVar(); } }, [urlParams.identity]); diff --git a/src/pages/orchestration/globalVar/index.tsx b/src/pages/orchestration/globalVar/index.tsx index 209ca1a..528f672 100644 --- a/src/pages/orchestration/globalVar/index.tsx +++ b/src/pages/orchestration/globalVar/index.tsx @@ -29,14 +29,12 @@ const GlobalVarContainer = () => { const [globalVarData, setGlobalVarData] = useState({}); // 存储全局变量数据 const [searchText, setSearchText] = useState(''); // 搜索文本 - // 获取所有数据类型键值 const menuItems = Object.keys(dataTypeMap); const getGlobalVar = async () => { try { const res: any = await getGlobalList(info.id); if (res.code === 200) { - // 初始化所有数据类型为空数组 const initData = {}; menuItems.forEach(item => { initData[item] = []; @@ -44,10 +42,10 @@ const GlobalVarContainer = () => { // 处理接口返回的数据,按类型分类 if (res.data) { - Object.keys(res.data).forEach(key => { - const item = res.data[key]; - if (item.dataType && initData[item.dataType]) { - initData[item.dataType].push(item); + Object.keys(res.data).forEach(dataType => { + const items = res.data[dataType]; + if (Array.isArray(items) && initData[dataType]) { + initData[dataType] = items; } }); } @@ -123,7 +121,6 @@ const GlobalVarContainer = () => { setSearchText(value); }; - // 使用 useMemo 优化搜索过滤 const filteredData = useMemo(() => { const currentData = globalVarData[selectedItem] || []; if (!searchText) { diff --git a/src/store/ideContainer.ts b/src/store/ideContainer.ts index 5c9e9e4..9bfff28 100644 --- a/src/store/ideContainer.ts +++ b/src/store/ideContainer.ts @@ -24,6 +24,7 @@ interface IDEContainerState { eventSendNodeList: any[], // [{nodeID:topic}] eventlisteneList: any[] // [{nodeID:topic}] }>; + gloBalVarList: any; } // 初始状态 @@ -41,7 +42,8 @@ const initialState: IDEContainerState = { socketId: '', // 工程的socketId nodeStatusMap: {}, // 初始化节点状态映射 isRunning: false, // 默认未运行 - appRuntimeData: {} // 按应用ID隔离的应用运行状态和日志数据 + appRuntimeData: {}, // 按应用ID隔离的应用运行状态和日志数据 + gloBalVarList: [] // 工程级全局变量列表 }; // 创建切片 @@ -82,6 +84,9 @@ const ideContainerSlice = createSlice({ updateSocketId(state, action) { state.socketId = action.payload; }, + updateGlobalVarList(state, action) { + state.gloBalVarList = action.payload; + }, // 更新节点状态 updateNodeStatus: (state, { payload }) => { const { nodeId, status, actionType } = payload; @@ -208,6 +213,7 @@ export const { updateEventTopicList, updateLogBarStatus, updateSocketId, + updateGlobalVarList, updateNodeStatus, resetNodeStatus, updateIsRunning,