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

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

@ -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]);

@ -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) {

@ -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,

Loading…
Cancel
Save