feat(ide): 添加工程级全局变量功能

master
钟良源 3 months ago
parent 66917cdfd2
commit f46827f869

@ -14,7 +14,8 @@ import {
updateCurrentAppData, updateCurrentAppData,
updateInfo, updateInfo,
updateProjectComponentData, updateProjectComponentData,
updateEventList updateEventList,
updateGlobalVarList
} from '@/store/ideContainer'; } from '@/store/ideContainer';
import { getAppListBySceneId } from '@/api/apps'; import { getAppListBySceneId } from '@/api/apps';
import { getProjectComp } from '@/api/scene'; import { getProjectComp } from '@/api/scene';
@ -32,6 +33,7 @@ import ComponentTest from '@/pages/componentDevelopment/componentTest';
import { getUserToken } from '@/api/user'; import { getUserToken } from '@/api/user';
import { Message } from '@arco-design/web-react'; import { Message } from '@arco-design/web-react';
import { queryEventItemBySceneId, queryEventItemBySceneIdOld } from '@/api/event'; import { queryEventItemBySceneId, queryEventItemBySceneIdOld } from '@/api/event';
import { getGlobalList } from '@/api/global';
type UrlParamsOptions = { type UrlParamsOptions = {
identity?: string; identity?: string;
@ -225,6 +227,11 @@ function IDEContainer() {
if (res1.code === 200) dispatch(updateEventListOld(res1.data)); 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(() => { useEffect(() => {
setUrlParams(getUrlParams(window.location.href) as UrlParamsOptions); setUrlParams(getUrlParams(window.location.href) as UrlParamsOptions);
dispatch(updateInfo(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') { if (urlParams.identity && urlParams.identity === 'scene') {
connectWS(); connectWS();
getEvent(); getEvent();
getGlobalVar();
} }
}, [urlParams.identity]); }, [urlParams.identity]);

@ -29,14 +29,12 @@ const GlobalVarContainer = () => {
const [globalVarData, setGlobalVarData] = useState({}); // 存储全局变量数据 const [globalVarData, setGlobalVarData] = useState({}); // 存储全局变量数据
const [searchText, setSearchText] = useState(''); // 搜索文本 const [searchText, setSearchText] = useState(''); // 搜索文本
// 获取所有数据类型键值
const menuItems = Object.keys(dataTypeMap); const menuItems = Object.keys(dataTypeMap);
const getGlobalVar = async () => { const getGlobalVar = async () => {
try { try {
const res: any = await getGlobalList(info.id); const res: any = await getGlobalList(info.id);
if (res.code === 200) { if (res.code === 200) {
// 初始化所有数据类型为空数组
const initData = {}; const initData = {};
menuItems.forEach(item => { menuItems.forEach(item => {
initData[item] = []; initData[item] = [];
@ -44,10 +42,10 @@ const GlobalVarContainer = () => {
// 处理接口返回的数据,按类型分类 // 处理接口返回的数据,按类型分类
if (res.data) { if (res.data) {
Object.keys(res.data).forEach(key => { Object.keys(res.data).forEach(dataType => {
const item = res.data[key]; const items = res.data[dataType];
if (item.dataType && initData[item.dataType]) { if (Array.isArray(items) && initData[dataType]) {
initData[item.dataType].push(item); initData[dataType] = items;
} }
}); });
} }
@ -123,7 +121,6 @@ const GlobalVarContainer = () => {
setSearchText(value); setSearchText(value);
}; };
// 使用 useMemo 优化搜索过滤
const filteredData = useMemo(() => { const filteredData = useMemo(() => {
const currentData = globalVarData[selectedItem] || []; const currentData = globalVarData[selectedItem] || [];
if (!searchText) { if (!searchText) {

@ -24,6 +24,7 @@ interface IDEContainerState {
eventSendNodeList: any[], // [{nodeID:topic}] eventSendNodeList: any[], // [{nodeID:topic}]
eventlisteneList: any[] // [{nodeID:topic}] eventlisteneList: any[] // [{nodeID:topic}]
}>; }>;
gloBalVarList: any;
} }
// 初始状态 // 初始状态
@ -41,7 +42,8 @@ const initialState: IDEContainerState = {
socketId: '', // 工程的socketId socketId: '', // 工程的socketId
nodeStatusMap: {}, // 初始化节点状态映射 nodeStatusMap: {}, // 初始化节点状态映射
isRunning: false, // 默认未运行 isRunning: false, // 默认未运行
appRuntimeData: {} // 按应用ID隔离的应用运行状态和日志数据 appRuntimeData: {}, // 按应用ID隔离的应用运行状态和日志数据
gloBalVarList: [] // 工程级全局变量列表
}; };
// 创建切片 // 创建切片
@ -82,6 +84,9 @@ const ideContainerSlice = createSlice({
updateSocketId(state, action) { updateSocketId(state, action) {
state.socketId = action.payload; state.socketId = action.payload;
}, },
updateGlobalVarList(state, action) {
state.gloBalVarList = action.payload;
},
// 更新节点状态 // 更新节点状态
updateNodeStatus: (state, { payload }) => { updateNodeStatus: (state, { payload }) => {
const { nodeId, status, actionType } = payload; const { nodeId, status, actionType } = payload;
@ -208,6 +213,7 @@ export const {
updateEventTopicList, updateEventTopicList,
updateLogBarStatus, updateLogBarStatus,
updateSocketId, updateSocketId,
updateGlobalVarList,
updateNodeStatus, updateNodeStatus,
resetNodeStatus, resetNodeStatus,
updateIsRunning, updateIsRunning,

Loading…
Cancel
Save