|
|
|
|
@ -15,7 +15,7 @@ import { localNodeData } from '@/pages/flowEditor/sideBar/config/localNodeData';
|
|
|
|
|
import { useAlignmentGuidelines } from '@/hooks/useAlignmentGuidelines';
|
|
|
|
|
import LocalNode from '@/components/FlowEditor/node/localNode/LocalNode';
|
|
|
|
|
import LoopNode from '@/components/FlowEditor/node/loopNode/LoopNode';
|
|
|
|
|
import { updateCanvasDataMap, resetNodeStatus, updateIsRunning } from '@/store/ideContainer';
|
|
|
|
|
import { updateCanvasDataMap, resetNodeStatus, updateIsRunning, updateEventListOld } from '@/store/ideContainer';
|
|
|
|
|
import {
|
|
|
|
|
validateAllNodes,
|
|
|
|
|
showValidationErrors,
|
|
|
|
|
@ -30,10 +30,11 @@ import { projectFlowHandle } from '@/pages/flowEditor/utils/projectFlowHandle';
|
|
|
|
|
import { appFLowHandle } from '@/pages/flowEditor/utils/appFlowhandle';
|
|
|
|
|
|
|
|
|
|
import { Dispatch } from 'redux';
|
|
|
|
|
import { runMainFlow } from '@/api/apps';
|
|
|
|
|
import { runMainFlow, stopApp } from '@/api/apps';
|
|
|
|
|
import store from '@/store';
|
|
|
|
|
import { updateAppEvent, updateAppEventChannel, updateAppFlowData } from '@/api/appEvent';
|
|
|
|
|
import { sleep } from '@/utils/common';
|
|
|
|
|
import { queryEventItemBySceneIdOld } from '@/api/event';
|
|
|
|
|
|
|
|
|
|
export const useFlowCallbacks = (
|
|
|
|
|
nodes: Node[],
|
|
|
|
|
@ -1004,7 +1005,7 @@ export const useFlowCallbacks = (
|
|
|
|
|
const emptyEvent = eventList.find(item => item.topic.includes('**empty**'));
|
|
|
|
|
newNode.data.component = {
|
|
|
|
|
type: nodeType,
|
|
|
|
|
customDef: { eventId: emptyEvent.eventId, name: emptyEvent.name, topic: emptyEvent.topic }
|
|
|
|
|
customDef: { eventId: emptyEvent?.eventId ?? null, name: emptyEvent.name, topic: emptyEvent.topic }
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
// 将未定义的节点动态追加进nodeTypes
|
|
|
|
|
@ -1080,27 +1081,29 @@ export const useFlowCallbacks = (
|
|
|
|
|
// 事件接收节点
|
|
|
|
|
params.eventListenes.push({
|
|
|
|
|
nodeName: nodeConfig.nodeName || '',
|
|
|
|
|
eventId: eventConfig?.eventId || '',
|
|
|
|
|
eventId: eventConfig?.eventId || null,
|
|
|
|
|
topic: eventConfig?.topic || '',
|
|
|
|
|
eventName: eventConfig?.name || '',
|
|
|
|
|
dataOuts: nodeConfig.dataOuts || []
|
|
|
|
|
dataOuts: nodeConfig.dataOuts || [],
|
|
|
|
|
nodeId: nodeConfig.nodeId
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (nodeType === 'EVENTSEND') {
|
|
|
|
|
// 事件发送节点
|
|
|
|
|
params.eventSends.push({
|
|
|
|
|
nodeName: nodeConfig.nodeName || '',
|
|
|
|
|
eventId: eventConfig?.eventId || '',
|
|
|
|
|
eventId: eventConfig?.eventId || null,
|
|
|
|
|
topic: eventConfig?.topic || '',
|
|
|
|
|
eventName: eventConfig?.name || '',
|
|
|
|
|
dataIns: nodeConfig.dataIns || []
|
|
|
|
|
dataIns: nodeConfig.dataIns || [],
|
|
|
|
|
nodeId: nodeConfig.nodeId
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
// 调用更新事件的API
|
|
|
|
|
if (params.eventListenes.length > 0 || params.eventSends.length > 0) {
|
|
|
|
|
updateAppEvent(appid, params);
|
|
|
|
|
return params;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const upDatePublish = async (revertedData) => {
|
|
|
|
|
@ -1139,20 +1142,23 @@ export const useFlowCallbacks = (
|
|
|
|
|
const revertedData = revertFlowData(nodes, edges);
|
|
|
|
|
const upDatePublishCB = await upDatePublish(revertedData.nodeConfigs);
|
|
|
|
|
const newRevertedData = reverseConvertFlowData(nodes, edges, upDatePublishCB);
|
|
|
|
|
const { flowData, currentAppData } = store.getState().ideContainer;
|
|
|
|
|
// console.log('revertedData:', revertedData);
|
|
|
|
|
// console.log('newRevertedData:', newRevertedData);
|
|
|
|
|
const { flowData, currentAppData, info } = store.getState().ideContainer;
|
|
|
|
|
let params = {};
|
|
|
|
|
// 更新复合组件/子流程
|
|
|
|
|
if (currentAppData.key.includes('sub')) {
|
|
|
|
|
const appEventDefinition = updateEvent(revertedData.nodeConfigs, initialData.appId);
|
|
|
|
|
params = {
|
|
|
|
|
...currentAppData?.compData || {},
|
|
|
|
|
components: newRevertedData
|
|
|
|
|
components: newRevertedData,
|
|
|
|
|
appEventDefinition,
|
|
|
|
|
sceneId: info.id
|
|
|
|
|
};
|
|
|
|
|
updateEvent(revertedData.nodeConfigs, currentAppData.parentAppId);
|
|
|
|
|
const res: any = await setSubFlowNew(params, currentAppData.parentAppId);
|
|
|
|
|
if (res.code === 200) {
|
|
|
|
|
Message.success('保存成功');
|
|
|
|
|
// 更新事件枚举表
|
|
|
|
|
const res1: any = await queryEventItemBySceneIdOld(info.id);
|
|
|
|
|
if (res1.code === 200) dispatch(updateEventListOld(res1.data));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
Message.error(res.message);
|
|
|
|
|
@ -1160,14 +1166,19 @@ export const useFlowCallbacks = (
|
|
|
|
|
}
|
|
|
|
|
// 更新主流程
|
|
|
|
|
else {
|
|
|
|
|
const appEventDefinition = updateEvent(revertedData.nodeConfigs, initialData.appId);
|
|
|
|
|
params = {
|
|
|
|
|
...flowData[currentAppData.id]?.main || {},
|
|
|
|
|
components: newRevertedData
|
|
|
|
|
components: newRevertedData,
|
|
|
|
|
appEventDefinition,
|
|
|
|
|
sceneId: info.id
|
|
|
|
|
};
|
|
|
|
|
updateEvent(revertedData.nodeConfigs, initialData.appId);
|
|
|
|
|
const res: any = await setMainFlowNew(params, initialData.appId);
|
|
|
|
|
if (res.code === 200) {
|
|
|
|
|
Message.success('保存成功');
|
|
|
|
|
// 更新事件枚举表
|
|
|
|
|
const res1: any = await queryEventItemBySceneIdOld(info.id);
|
|
|
|
|
if (res1.code === 200) dispatch(updateEventListOld(res1.data));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
Message.error(res.message);
|
|
|
|
|
@ -1196,33 +1207,45 @@ export const useFlowCallbacks = (
|
|
|
|
|
|
|
|
|
|
const eventMap = new Map();
|
|
|
|
|
edges.forEach((edge: any) => {
|
|
|
|
|
const eventId = edge.data.displayData.eventId;
|
|
|
|
|
const dto = {
|
|
|
|
|
eventId: eventId,
|
|
|
|
|
topicDTO: {
|
|
|
|
|
topic: edge.data.displayData.topic,
|
|
|
|
|
eventName: edge.data.displayData.name
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
eventMap.set(eventId, dto);
|
|
|
|
|
// 应用组件的桩点id就是事件id
|
|
|
|
|
const sourceId = edge.source;
|
|
|
|
|
const targetId = edge.target;
|
|
|
|
|
const topic = edge.data.displayData.topic;
|
|
|
|
|
|
|
|
|
|
if (eventMap.has(topic)) {
|
|
|
|
|
// 如果topic已存在,将eventId添加到数组中
|
|
|
|
|
eventMap.get(topic).eventId.push(sourceId);
|
|
|
|
|
eventMap.get(topic).eventId.push(targetId);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// 如果topic不存在,创建新的条目
|
|
|
|
|
eventMap.set(topic, {
|
|
|
|
|
eventId: [sourceId, targetId],
|
|
|
|
|
topic: topic
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
const appEventParams = Array.from(eventMap.values());
|
|
|
|
|
// 对eventId数组进行去重处理
|
|
|
|
|
const appEventParams = Array.from(eventMap.values()).map(item => ({
|
|
|
|
|
...item,
|
|
|
|
|
eventId: Array.from(new Set(item.eventId))
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
console.log('appEventParams:', appEventParams);
|
|
|
|
|
|
|
|
|
|
updateAppFlowData(appFlowParams);
|
|
|
|
|
if (appEventParams.length > 0) {
|
|
|
|
|
for (const item of appEventParams) {
|
|
|
|
|
console.log('item:', item);
|
|
|
|
|
await sleep(500);
|
|
|
|
|
updateAppEventChannel(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}, [nodes, edges, initialData?.appId]);
|
|
|
|
|
// 运行处理函数
|
|
|
|
|
const handleRun = useCallback(async (running: boolean) => {
|
|
|
|
|
const { currentAppData, socketId } = store.getState().ideContainer;
|
|
|
|
|
if (running) {
|
|
|
|
|
const { currentAppData, socketId } = store.getState().ideContainer;
|
|
|
|
|
// 启动运行
|
|
|
|
|
const params = {
|
|
|
|
|
appId: currentAppData.id,
|
|
|
|
|
@ -1250,6 +1273,8 @@ export const useFlowCallbacks = (
|
|
|
|
|
// 设置运行状态为false
|
|
|
|
|
dispatch(updateIsRunning(false));
|
|
|
|
|
|
|
|
|
|
stopApp(currentAppData.id);
|
|
|
|
|
|
|
|
|
|
// 停止运行
|
|
|
|
|
setEdges((eds) => eds.map(edge => ({
|
|
|
|
|
...edge,
|
|
|
|
|
|