feat(flow): 支持子流程保存与事件更新

master
钟良源 3 months ago
parent 30ed7d22e6
commit 2fb23fde80

@ -21,7 +21,7 @@ export function setMainFlow(data: FlowDefinition, appId: string) {
} }
// 更新主流程-新数据结构 // 更新主流程-新数据结构
export function setMainFlowNew(data: FlowDefinition, appId: string) { export function setMainFlowNew(data, appId: string) {
return axios.post(`${urlPrefix}/appRes/${appId}/updateMainNew`, data); return axios.post(`${urlPrefix}/appRes/${appId}/updateMainNew`, data);
} }
@ -51,6 +51,10 @@ export function setSubFlow(data: FlowDefinition, appId: string) {
return axios.post(`${urlPrefix}/appRes/${appId}/updateSub`, data); return axios.post(`${urlPrefix}/appRes/${appId}/updateSub`, data);
} }
export function setSubFlowNew(data, appId: string) {
return axios.post(`${urlPrefix}/appRes/${appId}/updateSubNew`, data);
}
// 导入子流程 // 导入子流程
export function addSubComp(data: appFlowModel, appId: string) { export function addSubComp(data: appFlowModel, appId: string) {
return axios.post(`${urlPrefix}/appRes/${appId}/addSubComp`, data); return axios.post(`${urlPrefix}/appRes/${appId}/addSubComp`, data);

@ -7,7 +7,7 @@ import {
Node, Node,
Edge Edge
} from '@xyflow/react'; } from '@xyflow/react';
import { refPublish, setMainFlow, setMainFlowNew } from '@/api/appRes'; import { refPublish, setMainFlow, setMainFlowNew, setSubFlowNew } from '@/api/appRes';
import { Message } from '@arco-design/web-react'; import { Message } from '@arco-design/web-react';
import { nodeTypeMap, registerNodeType } from '@/components/FlowEditor/node'; import { nodeTypeMap, registerNodeType } from '@/components/FlowEditor/node';
import { convertFlowData, reverseConvertFlowData, revertFlowData } from '@/utils/convertFlowData'; import { convertFlowData, reverseConvertFlowData, revertFlowData } from '@/utils/convertFlowData';
@ -1003,7 +1003,7 @@ export const useFlowCallbacks = (
const emptyEvent = eventList.find(item => item.topic.includes('**empty**')); const emptyEvent = eventList.find(item => item.topic.includes('**empty**'));
newNode.data.component = { newNode.data.component = {
type: nodeType, type: nodeType,
customDef: { eventId: emptyEvent.id, name: emptyEvent.name, topic: emptyEvent.topic } customDef: { eventId: emptyEvent.eventId, name: emptyEvent.name, topic: emptyEvent.topic }
}; };
} }
// 将未定义的节点动态追加进nodeTypes // 将未定义的节点动态追加进nodeTypes
@ -1046,7 +1046,7 @@ export const useFlowCallbacks = (
// endregion // endregion
// 保存所有节点和边数据到服务器,更新事件相关数据 // 保存所有节点和边数据到服务器,更新事件相关数据
const updateEvent = (revertedData) => { const updateEvent = (revertedData, appid) => {
// 初始化参数对象 // 初始化参数对象
const params: any = { const params: any = {
eventListenes: [], eventListenes: [],
@ -1098,8 +1098,8 @@ export const useFlowCallbacks = (
} }
}); });
// 调用更新事件的API // 调用更新事件的API
if (params.eventListenes.lengrh > 0 || params.eventSends.length > 0) { if (params.eventListenes.length > 0 || params.eventSends.length > 0) {
updateAppEvent(initialData.appId, params); updateAppEvent(appid, params);
} }
}; };
const upDatePublish = async (revertedData) => { const upDatePublish = async (revertedData) => {
@ -1141,21 +1141,36 @@ export const useFlowCallbacks = (
const { flowData, currentAppData } = store.getState().ideContainer; const { flowData, currentAppData } = store.getState().ideContainer;
// console.log('revertedData:', revertedData); // console.log('revertedData:', revertedData);
// console.log('newRevertedData:', newRevertedData); // console.log('newRevertedData:', newRevertedData);
const params = { let params = {};
...flowData[currentAppData.id]?.main || {}, // 更新复合组件/子流程
components: newRevertedData if (currentAppData.key.includes('sub')) {
}; params = {
// return; ...currentAppData?.compData || {},
updateEvent(revertedData.nodeConfigs); components: newRevertedData
// 旧版数据结构 };
// const res: any = await setMainFlow(revertedData, initialData.appId); updateEvent(revertedData.nodeConfigs, currentAppData.parentAppId);
// 新版数据结构 const res: any = await setSubFlowNew(params, currentAppData.parentAppId);
const res: any = await setMainFlowNew(params, initialData.appId); if (res.code === 200) {
if (res.code === 200) { Message.success('保存成功');
Message.success('保存成功'); }
else {
Message.error(res.message);
}
} }
// 更新主流程
else { else {
Message.error(res.message); params = {
...flowData[currentAppData.id]?.main || {},
components: newRevertedData
};
updateEvent(revertedData.nodeConfigs, initialData.appId);
const res: any = await setMainFlowNew(params, initialData.appId);
if (res.code === 200) {
Message.success('保存成功');
}
else {
Message.error(res.message);
}
} }
} catch (error) { } catch (error) {
console.error('Error saving flow data:', error); console.error('Error saving flow data:', error);
@ -1167,7 +1182,6 @@ export const useFlowCallbacks = (
nodes, nodes,
edges edges
}; };
console.log('params:', params);
} }
}, [nodes, edges, initialData?.appId]); }, [nodes, edges, initialData?.appId]);
// 运行处理函数 // 运行处理函数

@ -114,7 +114,6 @@ function IDEContainer() {
const currentSubComp = subCompList.find((item) => item.flowId === customDef.subflowId); const currentSubComp = subCompList.find((item) => item.flowId === customDef.subflowId);
// 根据节点信息创建新的标签页 // 根据节点信息创建新的标签页
if (currentSubComp && Object.keys(currentSubComp).length > 0) { if (currentSubComp && Object.keys(currentSubComp).length > 0) {
const component = node.data.component;
const newNodeKey = currentSubComp.flowId; const newNodeKey = currentSubComp.flowId;
// 查找菜单项 // 查找菜单项
@ -153,6 +152,7 @@ function IDEContainer() {
pathTitle: `${currentAppData.name} / ${currentSubComp.flowName}`, pathTitle: `${currentAppData.name} / ${currentSubComp.flowName}`,
path: 'complexFlow', path: 'complexFlow',
parentKey: 'appList', parentKey: 'appList',
parentAppId: currentAppData.id,
compData: currentSubComp, compData: currentSubComp,
children: null children: null
}; };
@ -175,7 +175,7 @@ function IDEContainer() {
return () => { return () => {
document.removeEventListener('openSubNodeTab', handleOpenSubNodeTab as EventListener); document.removeEventListener('openSubNodeTab', handleOpenSubNodeTab as EventListener);
}; };
}, [menuData, urlParams.identity, dispatch]); }, [menuData, flowData, currentAppData]);
const connectWS = async () => { const connectWS = async () => {
const res = await getUserToken(); const res = await getUserToken();

@ -345,7 +345,8 @@ const SideBar: React.FC<SideBarProps> = ({
path: 'complexFlow', path: 'complexFlow',
key: info.flowId, key: info.flowId,
pathTitle: `${data.title} / ${info.flowName}`, pathTitle: `${data.title} / ${info.flowName}`,
parentKey: 'appList' parentKey: 'appList',
parentAppId: data.id
}; };
}) })
}; };

Loading…
Cancel
Save