diff --git a/src/api/appRes.ts b/src/api/appRes.ts index 8e40c69..3781f29 100644 --- a/src/api/appRes.ts +++ b/src/api/appRes.ts @@ -25,6 +25,11 @@ export function setMainFlowNew(data: FlowDefinition, appId: string) { return axios.post(`${urlPrefix}/appRes/${appId}/updateMainNew`, data); } +// 引用公开组件到应用组件内 +export function refPublish(data) { + return axios.put(`${urlPrefix}/appRes/refPublish`, data); +} + // 新增子流程 export function addSub(appId: string, data?: FlowDefinition[]) { return axios.post( diff --git a/src/components/FlowEditor/node/index.tsx b/src/components/FlowEditor/node/index.tsx index 5567e47..0d39d40 100644 --- a/src/components/FlowEditor/node/index.tsx +++ b/src/components/FlowEditor/node/index.tsx @@ -15,6 +15,7 @@ export const nodeTypes: NodeTypes = { start: StartNode, end: EndNode, BASIC: BasicNode, + SUB: BasicNode, APP: AppNode, CODE: CodeNode, IMAGE: ImageNode, @@ -28,6 +29,7 @@ export const nodeTypeMap: Record = { 'start': 'start', 'end': 'end', 'basic': 'BASIC', + 'sub': 'SUB', 'app': 'APP', 'code': 'CODE', 'image': 'IMAGE', @@ -41,6 +43,7 @@ export const nodeTypeNameMap: Record = { 'start': '开始节点', 'end': '结束节点', 'basic': '基础节点', + 'sub': '复合节点', 'app': '应用节点', 'code': '代码节点', 'image': '图片节点', diff --git a/src/hooks/useFlowCallbacks.ts b/src/hooks/useFlowCallbacks.ts index e54cdff..d1ad44c 100644 --- a/src/hooks/useFlowCallbacks.ts +++ b/src/hooks/useFlowCallbacks.ts @@ -7,7 +7,7 @@ import { Node, Edge } from '@xyflow/react'; -import { setMainFlow, setMainFlowNew } from '@/api/appRes'; +import { refPublish, setMainFlow, setMainFlowNew } from '@/api/appRes'; import { Message } from '@arco-design/web-react'; import { nodeTypeMap, registerNodeType } from '@/components/FlowEditor/node'; import { convertFlowData, reverseConvertFlowData, revertFlowData } from '@/utils/convertFlowData'; @@ -60,8 +60,7 @@ export const useFlowCallbacks = ( setEdgeForNodeAdd: React.Dispatch>, positionForNodeAdd: { x: number, y: number } | null, setPositionForNodeAdd: React.Dispatch>, - setIsDelete: React.Dispatch>, - setIsRunning: React.Dispatch> + setIsDelete: React.Dispatch> ) => { const { getGuidelines, clearGuidelines } = useAlignmentGuidelines(); // region 画布操作 @@ -633,7 +632,7 @@ export const useFlowCallbacks = ( ...nodeDefinition.data, title: nodeDefinition.nodeName, type: nodeType, - compId: nodeDefinition.id + compId: nodeDefinition.id || nodeDefinition.flowHousVO.id } }; @@ -750,7 +749,7 @@ export const useFlowCallbacks = ( ...nodeDefinition.data, title: nodeDefinition.nodeName, type: nodeType, - compId: nodeDefinition.id + compId: nodeDefinition.id || nodeDefinition.flowHousVO.id } }; @@ -770,7 +769,6 @@ export const useFlowCallbacks = ( customDef: { eventId: emptyEvent.id, name: emptyEvent.name, topic: emptyEvent.topic } }; } - // 将未定义的节点动态追加进nodeTypes const nodeMap = Array.from(Object.values(nodeTypeMap).map(key => key)); // 目前默认添加的都是系统组件/本地组件 @@ -867,6 +865,17 @@ export const useFlowCallbacks = ( updateAppEvent(initialData.appId, params); } }; + const upDatePublish = (revertedData) => { + const { currentAppData } = store.getState().ideContainer; + const params = { + appId: currentAppData.id, + publishAppId: [] + }; + revertedData.forEach(item => { + if (item?.component && item.component.type === 'SUB') params.publishAppId.push(item.component.compId); // 复合组件的这个compId实际上就是flowHousVO里面的id + }); + if (params.publishAppId.length > 0) refPublish(params); + }; const saveFlowDataToServer = useCallback(async () => { if (useDefault) { try { @@ -895,7 +904,7 @@ export const useFlowCallbacks = ( components: newRevertedData }; // return; - + upDatePublish(revertedData.nodeConfigs); updateEvent(revertedData.nodeConfigs); // 旧版数据结构 // const res: any = await setMainFlow(revertedData, initialData.appId); diff --git a/src/pages/flowEditor/FlowEditorMain.tsx b/src/pages/flowEditor/FlowEditorMain.tsx index 4f22aa8..6e02e39 100644 --- a/src/pages/flowEditor/FlowEditorMain.tsx +++ b/src/pages/flowEditor/FlowEditorMain.tsx @@ -51,7 +51,6 @@ interface FlowEditorMainProps { positionForNodeAdd: { x: number, y: number } | null; setPositionForNodeAdd: React.Dispatch>; isRunning: boolean; - setIsRunning: React.Dispatch>; initialData: any; canvasDataMap: any; diff --git a/src/pages/flowEditor/components/addNodeMenu.tsx b/src/pages/flowEditor/components/addNodeMenu.tsx index 98c8d41..f44d58a 100644 --- a/src/pages/flowEditor/components/addNodeMenu.tsx +++ b/src/pages/flowEditor/components/addNodeMenu.tsx @@ -59,7 +59,7 @@ const AddNodeMenu: React.FC = ({ return { ...v, nodeName: v?.main?.name || '复合组件', - nodeType: 'BASIC', + nodeType: 'SUB', nodeGroup: 'composite', data: { parameters: { diff --git a/src/pages/flowEditor/index.tsx b/src/pages/flowEditor/index.tsx index 94835d8..247cc6d 100644 --- a/src/pages/flowEditor/index.tsx +++ b/src/pages/flowEditor/index.tsx @@ -53,7 +53,6 @@ const FlowEditor: React.FC<{ initialData?: any, useDefault?: boolean }> = ({ ini positionForNodeAdd, setPositionForNodeAdd, isRunning, - setIsRunning, historyInitialized, setHistoryInitialized, historyTimeoutRef, @@ -120,8 +119,7 @@ const FlowEditor: React.FC<{ initialData?: any, useDefault?: boolean }> = ({ ini setEdgeForNodeAdd, positionForNodeAdd, setPositionForNodeAdd, - setIsDelete, - setIsRunning + setIsDelete ); // 节点右键菜单处理 @@ -275,7 +273,6 @@ const FlowEditor: React.FC<{ initialData?: any, useDefault?: boolean }> = ({ ini positionForNodeAdd={positionForNodeAdd} setPositionForNodeAdd={setPositionForNodeAdd} isRunning={isRunning} - setIsRunning={setIsRunning} initialData={initialData} canvasDataMap={canvasDataMap} diff --git a/src/utils/convertFlowData.ts b/src/utils/convertFlowData.ts index 39f5e8c..417bb30 100644 --- a/src/utils/convertFlowData.ts +++ b/src/utils/convertFlowData.ts @@ -333,7 +333,6 @@ export const convertFlowData = (flowData: any, useDefault = true) => { }); } } - return { nodes, edges }; }; @@ -396,7 +395,7 @@ export const revertFlowData = (nodes: any[], edges: any[]) => { type: nodeType }; } - if (['BASIC'].includes(nodeType)) nodeConfig.component.compId = node.data.compId || ''; + if (['BASIC', 'SUB'].includes(nodeType)) nodeConfig.component.compId = node.data.compId || ''; // 处理参数信息 const parameters = node.data?.parameters || {}; @@ -776,6 +775,7 @@ const getCurrentProjectStoreData = () => { const getNodeComponent = (nodeType: string) => { switch (nodeType) { case 'BASIC': + case 'SUB': return BasicNode; case 'SWITCH': return SwitchNode; diff --git a/src/utils/flowCommon.ts b/src/utils/flowCommon.ts index ee4cc19..9cf3f37 100644 --- a/src/utils/flowCommon.ts +++ b/src/utils/flowCommon.ts @@ -81,6 +81,7 @@ const validateDataType = (sourceNode: defaultNodeTypes, targetNode: defaultNodeT const getNodeComponent = (nodeType: string) => { switch (nodeType) { case 'BASIC': + case 'SUB': return BasicNode; case 'SWITCH': return SwitchNode;