|
|
|
@ -36,13 +36,14 @@ import {
|
|
|
|
} from '@/utils/flowCommon';
|
|
|
|
} from '@/utils/flowCommon';
|
|
|
|
import { projectFlowHandle } from '@/pages/flowEditor/utils/projectFlowHandle';
|
|
|
|
import { projectFlowHandle } from '@/pages/flowEditor/utils/projectFlowHandle';
|
|
|
|
import { appFLowHandle } from '@/pages/flowEditor/utils/appFlowhandle';
|
|
|
|
import { appFLowHandle } from '@/pages/flowEditor/utils/appFlowhandle';
|
|
|
|
|
|
|
|
import { handelEventNodeList, updateEvent, upDatePublish } from '@/pages/flowEditor/utils/common';
|
|
|
|
|
|
|
|
|
|
|
|
import { Dispatch } from 'redux';
|
|
|
|
import { Dispatch } from 'redux';
|
|
|
|
import { runMainFlow, stopApp } from '@/api/apps';
|
|
|
|
import { runMainFlow, stopApp } from '@/api/apps';
|
|
|
|
import store from '@/store';
|
|
|
|
import store from '@/store';
|
|
|
|
import { updateAppEvent, updateAppEventChannel, updateAppFlowData } from '@/api/appEvent';
|
|
|
|
import { updateAppEvent, updateAppEventChannel, updateAppFlowData } from '@/api/appEvent';
|
|
|
|
import { sleep } from '@/utils/common';
|
|
|
|
import { sleep } from '@/utils/common';
|
|
|
|
import { queryEventItemBySceneIdOld } from '@/api/event';
|
|
|
|
import { queryEventItemBySceneIdOld, deleteEventSub, deleteEventPub } from '@/api/event';
|
|
|
|
|
|
|
|
|
|
|
|
export const useFlowCallbacks = (
|
|
|
|
export const useFlowCallbacks = (
|
|
|
|
nodes: Node[],
|
|
|
|
nodes: Node[],
|
|
|
|
@ -810,7 +811,11 @@ export const useFlowCallbacks = (
|
|
|
|
target: loopStartNode.id,
|
|
|
|
target: loopStartNode.id,
|
|
|
|
sourceHandle: edgeForNodeAdd.sourceHandle,
|
|
|
|
sourceHandle: edgeForNodeAdd.sourceHandle,
|
|
|
|
targetHandle: 'start', // 循环开始节点的输入句柄
|
|
|
|
targetHandle: 'start', // 循环开始节点的输入句柄
|
|
|
|
type: 'custom'
|
|
|
|
type: 'custom',
|
|
|
|
|
|
|
|
lineType: 'api',
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
lineType: 'api'
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
id: `e${loopEndNode.id}-${edgeForNodeAdd.target}`,
|
|
|
|
id: `e${loopEndNode.id}-${edgeForNodeAdd.target}`,
|
|
|
|
@ -818,7 +823,11 @@ export const useFlowCallbacks = (
|
|
|
|
target: edgeForNodeAdd.target,
|
|
|
|
target: edgeForNodeAdd.target,
|
|
|
|
sourceHandle: 'break', // 循环结束节点的输出句柄
|
|
|
|
sourceHandle: 'break', // 循环结束节点的输出句柄
|
|
|
|
targetHandle: edgeForNodeAdd.targetHandle,
|
|
|
|
targetHandle: edgeForNodeAdd.targetHandle,
|
|
|
|
type: 'custom'
|
|
|
|
type: 'custom',
|
|
|
|
|
|
|
|
lineType: 'api',
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
lineType: 'api'
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
@ -977,7 +986,11 @@ export const useFlowCallbacks = (
|
|
|
|
target: newNode.id,
|
|
|
|
target: newNode.id,
|
|
|
|
sourceHandle: edgeForNodeAdd.sourceHandle,
|
|
|
|
sourceHandle: edgeForNodeAdd.sourceHandle,
|
|
|
|
targetHandle: newNodeTargetHandle,
|
|
|
|
targetHandle: newNodeTargetHandle,
|
|
|
|
type: 'custom'
|
|
|
|
type: 'custom',
|
|
|
|
|
|
|
|
lineType: 'api',
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
lineType: 'api'
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
id: `e${newNode.id}-${edgeForNodeAdd.target}`,
|
|
|
|
id: `e${newNode.id}-${edgeForNodeAdd.target}`,
|
|
|
|
@ -985,7 +998,11 @@ export const useFlowCallbacks = (
|
|
|
|
target: edgeForNodeAdd.target,
|
|
|
|
target: edgeForNodeAdd.target,
|
|
|
|
sourceHandle: newNodeSourceHandle,
|
|
|
|
sourceHandle: newNodeSourceHandle,
|
|
|
|
targetHandle: edgeForNodeAdd.targetHandle,
|
|
|
|
targetHandle: edgeForNodeAdd.targetHandle,
|
|
|
|
type: 'custom'
|
|
|
|
type: 'custom',
|
|
|
|
|
|
|
|
lineType: 'api',
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
lineType: 'api'
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
@ -1111,168 +1128,7 @@ export const useFlowCallbacks = (
|
|
|
|
}, [edgeForNodeAdd, positionForNodeAdd, addNodeOnEdge, addNodeOnPane]);
|
|
|
|
}, [edgeForNodeAdd, positionForNodeAdd, addNodeOnEdge, addNodeOnPane]);
|
|
|
|
// endregion
|
|
|
|
// endregion
|
|
|
|
|
|
|
|
|
|
|
|
// 保存所有节点和边数据到服务器,更新事件相关数据
|
|
|
|
|
|
|
|
const updateEvent = (revertedData, appid) => {
|
|
|
|
|
|
|
|
// 初始化参数对象
|
|
|
|
|
|
|
|
const params: any = {
|
|
|
|
|
|
|
|
eventListenes: [],
|
|
|
|
|
|
|
|
eventSends: []
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 遍历所有节点,查找事件相关节点
|
|
|
|
|
|
|
|
Object.entries(revertedData).forEach(([nodeId, nodeConfig]: [string, any]) => {
|
|
|
|
|
|
|
|
// 检查节点是否有component属性和type定义
|
|
|
|
|
|
|
|
if (nodeConfig.component?.type) {
|
|
|
|
|
|
|
|
const nodeType = nodeConfig.component.type;
|
|
|
|
|
|
|
|
const customDef = nodeConfig.component.customDef;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 解析customDef,可能是字符串也可能是对象
|
|
|
|
|
|
|
|
let eventConfig;
|
|
|
|
|
|
|
|
if (typeof customDef === 'string') {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
eventConfig = JSON.parse(customDef);
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
console.error('Failed to parse customDef:', e);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
eventConfig = customDef;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 根据节点类型处理事件节点
|
|
|
|
|
|
|
|
if (nodeType === 'EVENTLISTENE') {
|
|
|
|
|
|
|
|
// 事件接收节点
|
|
|
|
|
|
|
|
params.eventListenes.push({
|
|
|
|
|
|
|
|
nodeName: nodeConfig.nodeName || '',
|
|
|
|
|
|
|
|
eventId: eventConfig?.eventId || null,
|
|
|
|
|
|
|
|
topic: eventConfig?.topic || '',
|
|
|
|
|
|
|
|
eventName: eventConfig?.name || '',
|
|
|
|
|
|
|
|
dataOuts: nodeConfig.dataOuts || [],
|
|
|
|
|
|
|
|
nodeId: nodeConfig.nodeId
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (nodeType === 'EVENTSEND') {
|
|
|
|
|
|
|
|
// 事件发送节点
|
|
|
|
|
|
|
|
params.eventSends.push({
|
|
|
|
|
|
|
|
nodeName: nodeConfig.nodeName || '',
|
|
|
|
|
|
|
|
eventId: eventConfig?.eventId || null,
|
|
|
|
|
|
|
|
topic: eventConfig?.topic || '',
|
|
|
|
|
|
|
|
eventName: eventConfig?.name || '',
|
|
|
|
|
|
|
|
dataIns: nodeConfig.dataIns || [],
|
|
|
|
|
|
|
|
nodeId: nodeConfig.nodeId
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
// 调用更新事件的API
|
|
|
|
|
|
|
|
if (params.eventListenes.length > 0 || params.eventSends.length > 0) {
|
|
|
|
|
|
|
|
return params;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else return null;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
const upDatePublish = async (revertedData) => {
|
|
|
|
|
|
|
|
const { currentAppData } = store.getState().ideContainer;
|
|
|
|
|
|
|
|
const params = {
|
|
|
|
|
|
|
|
appId: currentAppData.id,
|
|
|
|
|
|
|
|
publishAppId: []
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
revertedData.forEach(item => {
|
|
|
|
|
|
|
|
if (item?.component && item.component.type === 'SUB' && !item.component.customDef) params.publishAppId.push(item.component.compId); // 复合组件的这个compId实际上就是flowHousVO里面的id
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
if (params.publishAppId.length > 0) {
|
|
|
|
|
|
|
|
const res: any = await refPublish(params);
|
|
|
|
|
|
|
|
if (res.code === 200) return res.data;
|
|
|
|
|
|
|
|
else return {};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else return {};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
const handelEventNodeList = (newRevertedData) => {
|
|
|
|
|
|
|
|
const { appRuntimeData, currentAppData } = store.getState().ideContainer;
|
|
|
|
|
|
|
|
const current = appRuntimeData[currentAppData.id];
|
|
|
|
|
|
|
|
const deleteEventSendNodeList = [];
|
|
|
|
|
|
|
|
const deleteEventlisteneList = [];
|
|
|
|
|
|
|
|
// 处理流程接口后的数据
|
|
|
|
|
|
|
|
const currentEventSendNodeList = current.eventSendNodeList;
|
|
|
|
|
|
|
|
const currentEventlisteneList = current.eventlisteneList;
|
|
|
|
|
|
|
|
// 画布数据
|
|
|
|
|
|
|
|
const nodeEntries: [string, any][] = Object.entries(newRevertedData);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 分类事件节点
|
|
|
|
|
|
|
|
const eventSendNodes = [];
|
|
|
|
|
|
|
|
const eventListenerNodes = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 从nodeEntries中提取事件节点
|
|
|
|
|
|
|
|
nodeEntries.forEach(([nodeId, nodeConfig]) => {
|
|
|
|
|
|
|
|
if (nodeConfig.component?.type === 'EVENTSEND') {
|
|
|
|
|
|
|
|
eventSendNodes.push({ nodeId, ...nodeConfig });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (nodeConfig.component?.type === 'EVENTLISTENE') {
|
|
|
|
|
|
|
|
eventListenerNodes.push({ nodeId, ...nodeConfig });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 处理EVENTSEND节点
|
|
|
|
|
|
|
|
// 如果currentEventSendNodeList中有而nodeEntries中没有,则加入删除列表
|
|
|
|
|
|
|
|
currentEventSendNodeList.forEach((eventNode) => {
|
|
|
|
|
|
|
|
const nodeId = eventNode;
|
|
|
|
|
|
|
|
const nodeInCanvas = eventSendNodes.find(node => node.nodeId === nodeId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!nodeInCanvas) {
|
|
|
|
|
|
|
|
// 画布数据中没有该节点,加入删除列表
|
|
|
|
|
|
|
|
deleteEventSendNodeList.push(eventNode);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
// 节点存在于画布中,比较时间戳
|
|
|
|
|
|
|
|
// nodeId格式为"节点类型-时间戳"
|
|
|
|
|
|
|
|
const canvasNode = nodeInCanvas.nodeId.split('-');
|
|
|
|
|
|
|
|
const canvasTimestamp = canvasNode[canvasNode.length - 1];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const interfaceNode = nodeId.split('-');
|
|
|
|
|
|
|
|
const interfaceTimestamp = interfaceNode[interfaceNode.length - 1];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果画布数据的时间戳是最新的,那就是新增的事件节点,不需要添加到deleteList中
|
|
|
|
|
|
|
|
// 反之需要进一步判断
|
|
|
|
|
|
|
|
if (canvasTimestamp < interfaceTimestamp) {
|
|
|
|
|
|
|
|
// 画布节点时间戳较旧,需要进一步判断
|
|
|
|
|
|
|
|
// 这里留空,等待后续实现
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 处理EVENTLISTENE节点
|
|
|
|
|
|
|
|
// 如果currentEventlisteneList中有而nodeEntries中没有,则加入删除列表
|
|
|
|
|
|
|
|
currentEventlisteneList.forEach((eventNode) => {
|
|
|
|
|
|
|
|
const nodeId = eventNode;
|
|
|
|
|
|
|
|
const nodeInCanvas = eventListenerNodes.find(node => node.nodeId === nodeId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!nodeInCanvas) {
|
|
|
|
|
|
|
|
// 画布数据中没有该节点,加入删除列表
|
|
|
|
|
|
|
|
deleteEventlisteneList.push(eventNode);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
// 节点存在于画布中,比较时间戳
|
|
|
|
|
|
|
|
// nodeId格式为"节点类型-时间戳"
|
|
|
|
|
|
|
|
const canvasNode = nodeInCanvas.nodeId.split('-');
|
|
|
|
|
|
|
|
const canvasTimestamp = canvasNode[canvasNode.length - 1];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const interfaceNode = nodeId.split('-');
|
|
|
|
|
|
|
|
const interfaceTimestamp = interfaceNode[interfaceNode.length - 1];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果画布数据的时间戳是最新的,那就是新增的事件节点,不需要添加到deleteList中
|
|
|
|
|
|
|
|
// 反之需要进一步判断
|
|
|
|
|
|
|
|
if (canvasTimestamp < interfaceTimestamp) {
|
|
|
|
|
|
|
|
// 画布节点时间戳较旧,需要进一步判断
|
|
|
|
|
|
|
|
// 这里留空,等待后续实现
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
deleteEventSendNodeList,
|
|
|
|
|
|
|
|
deleteEventlisteneList
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
const saveFlowDataToServer = useCallback(async () => {
|
|
|
|
const saveFlowDataToServer = useCallback(async () => {
|
|
|
|
if (useDefault) {
|
|
|
|
if (useDefault) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
@ -1295,7 +1151,7 @@ export const useFlowCallbacks = (
|
|
|
|
const newRevertedData = reverseConvertFlowData(nodes, edges, upDatePublishCB);
|
|
|
|
const newRevertedData = reverseConvertFlowData(nodes, edges, upDatePublishCB);
|
|
|
|
const { flowData, currentAppData, info } = store.getState().ideContainer;
|
|
|
|
const { flowData, currentAppData, info } = store.getState().ideContainer;
|
|
|
|
const { deleteEventSendNodeList, deleteEventlisteneList } = handelEventNodeList(newRevertedData);
|
|
|
|
const { deleteEventSendNodeList, deleteEventlisteneList } = handelEventNodeList(newRevertedData);
|
|
|
|
// console.log(deleteEventSendNodeList, deleteEventlisteneList);
|
|
|
|
console.log('事件处理数据', deleteEventSendNodeList, deleteEventlisteneList);
|
|
|
|
// return;
|
|
|
|
// return;
|
|
|
|
let params = {};
|
|
|
|
let params = {};
|
|
|
|
// 更新复合组件/子流程
|
|
|
|
// 更新复合组件/子流程
|
|
|
|
@ -1344,6 +1200,18 @@ export const useFlowCallbacks = (
|
|
|
|
Message.error(res.message);
|
|
|
|
Message.error(res.message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 事件节点变动数据有长度就通知后端,主流程和子流程(复合节点)通用
|
|
|
|
|
|
|
|
if (deleteEventSendNodeList.length > 0 || deleteEventlisteneList.length > 0) {
|
|
|
|
|
|
|
|
deleteEventSendNodeList.length > 0 && deleteEventPub({
|
|
|
|
|
|
|
|
appId: currentAppData.id,
|
|
|
|
|
|
|
|
topics: deleteEventSendNodeList
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
deleteEventlisteneList.length > 0 && deleteEventSub({
|
|
|
|
|
|
|
|
appId: currentAppData.id,
|
|
|
|
|
|
|
|
topics: deleteEventlisteneList
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Error saving flow data:', error);
|
|
|
|
console.error('Error saving flow data:', error);
|
|
|
|
Message.error('保存失败');
|
|
|
|
Message.error('保存失败');
|
|
|
|
@ -1391,7 +1259,7 @@ export const useFlowCallbacks = (
|
|
|
|
eventId: Array.from(new Set(item.eventId))
|
|
|
|
eventId: Array.from(new Set(item.eventId))
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
updateAppFlowData(appFlowParams);
|
|
|
|
updateAppFlowData(appEventParams);
|
|
|
|
if (appEventParams.length > 0) {
|
|
|
|
if (appEventParams.length > 0) {
|
|
|
|
for (const item of appEventParams) {
|
|
|
|
for (const item of appEventParams) {
|
|
|
|
await sleep(500);
|
|
|
|
await sleep(500);
|
|
|
|
|