diff --git a/src/api/appRes.ts b/src/api/appRes.ts index 3781f29..09833f6 100644 --- a/src/api/appRes.ts +++ b/src/api/appRes.ts @@ -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); } @@ -51,6 +51,10 @@ export function setSubFlow(data: FlowDefinition, appId: string) { 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) { return axios.post(`${urlPrefix}/appRes/${appId}/addSubComp`, data); diff --git a/src/hooks/useFlowCallbacks.ts b/src/hooks/useFlowCallbacks.ts index 9139cf4..3a4e292 100644 --- a/src/hooks/useFlowCallbacks.ts +++ b/src/hooks/useFlowCallbacks.ts @@ -7,7 +7,7 @@ import { Node, Edge } 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 { nodeTypeMap, registerNodeType } from '@/components/FlowEditor/node'; import { convertFlowData, reverseConvertFlowData, revertFlowData } from '@/utils/convertFlowData'; @@ -1003,7 +1003,7 @@ export const useFlowCallbacks = ( const emptyEvent = eventList.find(item => item.topic.includes('**empty**')); newNode.data.component = { type: nodeType, - customDef: { eventId: emptyEvent.id, name: emptyEvent.name, topic: emptyEvent.topic } + customDef: { eventId: emptyEvent.eventId, name: emptyEvent.name, topic: emptyEvent.topic } }; } // 将未定义的节点动态追加进nodeTypes @@ -1046,7 +1046,7 @@ export const useFlowCallbacks = ( // endregion // 保存所有节点和边数据到服务器,更新事件相关数据 - const updateEvent = (revertedData) => { + const updateEvent = (revertedData, appid) => { // 初始化参数对象 const params: any = { eventListenes: [], @@ -1098,8 +1098,8 @@ export const useFlowCallbacks = ( } }); // 调用更新事件的API - if (params.eventListenes.lengrh > 0 || params.eventSends.length > 0) { - updateAppEvent(initialData.appId, params); + if (params.eventListenes.length > 0 || params.eventSends.length > 0) { + updateAppEvent(appid, params); } }; const upDatePublish = async (revertedData) => { @@ -1141,21 +1141,36 @@ export const useFlowCallbacks = ( const { flowData, currentAppData } = store.getState().ideContainer; // console.log('revertedData:', revertedData); // console.log('newRevertedData:', newRevertedData); - const params = { - ...flowData[currentAppData.id]?.main || {}, - components: newRevertedData - }; - // return; - updateEvent(revertedData.nodeConfigs); - // 旧版数据结构 - // const res: any = await setMainFlow(revertedData, initialData.appId); - // 新版数据结构 - const res: any = await setMainFlowNew(params, initialData.appId); - if (res.code === 200) { - Message.success('保存成功'); + let params = {}; + // 更新复合组件/子流程 + if (currentAppData.key.includes('sub')) { + params = { + ...currentAppData?.compData || {}, + components: newRevertedData + }; + updateEvent(revertedData.nodeConfigs, currentAppData.parentAppId); + const res: any = await setSubFlowNew(params, currentAppData.parentAppId); + if (res.code === 200) { + Message.success('保存成功'); + } + else { + Message.error(res.message); + } } + // 更新主流程 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) { console.error('Error saving flow data:', error); @@ -1167,7 +1182,6 @@ export const useFlowCallbacks = ( nodes, edges }; - console.log('params:', params); } }, [nodes, edges, initialData?.appId]); // 运行处理函数 diff --git a/src/pages/ideContainer/index.tsx b/src/pages/ideContainer/index.tsx index 8ecba14..ce6f8c6 100644 --- a/src/pages/ideContainer/index.tsx +++ b/src/pages/ideContainer/index.tsx @@ -114,7 +114,6 @@ function IDEContainer() { const currentSubComp = subCompList.find((item) => item.flowId === customDef.subflowId); // 根据节点信息创建新的标签页 if (currentSubComp && Object.keys(currentSubComp).length > 0) { - const component = node.data.component; const newNodeKey = currentSubComp.flowId; // 查找菜单项 @@ -153,6 +152,7 @@ function IDEContainer() { pathTitle: `${currentAppData.name} / ${currentSubComp.flowName}`, path: 'complexFlow', parentKey: 'appList', + parentAppId: currentAppData.id, compData: currentSubComp, children: null }; @@ -175,7 +175,7 @@ function IDEContainer() { return () => { document.removeEventListener('openSubNodeTab', handleOpenSubNodeTab as EventListener); }; - }, [menuData, urlParams.identity, dispatch]); + }, [menuData, flowData, currentAppData]); const connectWS = async () => { const res = await getUserToken(); diff --git a/src/pages/ideContainer/sideBar.tsx b/src/pages/ideContainer/sideBar.tsx index f493520..4c988f0 100644 --- a/src/pages/ideContainer/sideBar.tsx +++ b/src/pages/ideContainer/sideBar.tsx @@ -345,7 +345,8 @@ const SideBar: React.FC = ({ path: 'complexFlow', key: info.flowId, pathTitle: `${data.title} / ${info.flowName}`, - parentKey: 'appList' + parentKey: 'appList', + parentAppId: data.id }; }) };