feat(flow):优化复合组件ID处理逻辑

master
钟良源 3 months ago
parent 11a0f992c0
commit 12d6e89b6e

@ -39,10 +39,10 @@ import { appFLowHandle } from '@/pages/flowEditor/utils/appFlowhandle';
import { handelEventNodeList, updateEvent, upDatePublish } from '@/pages/flowEditor/utils/common'; import { handelEventNodeList, updateEvent, upDatePublish } from '@/pages/flowEditor/utils/common';
import { Dispatch } from 'redux'; import { Dispatch } from 'redux';
import { runMainFlow, stopApp } from '@/api/apps'; import { getAppListBySceneId, 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 { getUrlParams, sleep } from '@/utils/common';
import { queryEventItemBySceneIdOld, deleteEventSub, deleteEventPub } from '@/api/event'; import { queryEventItemBySceneIdOld, deleteEventSub, deleteEventPub } from '@/api/event';
export const useFlowCallbacks = ( export const useFlowCallbacks = (
@ -912,26 +912,10 @@ export const useFlowCallbacks = (
}; };
} }
else if (nodeType === 'SUB') { else if (nodeType === 'SUB') {
const flowSubMap = flowData[currentAppData.id]?.subMap || {}; newNode.data.component = {
const sameData: any = flowSubMap[newNode.data.compId]; type: nodeType,
if (sameData) { compId: newNode.data.compId
newNode.data.component = { };
type: nodeType,
compId: newNode.data.compId,
customDef: JSON.stringify({
dataIns: newNode.data.parameters.dataIns,
dataOuts: newNode.data.parameters.dataOuts,
subflowId: sameData,
name: newNode.data.title
})
};
}
else {
newNode.data.component = {
type: nodeType,
compId: newNode.data.compId
};
}
} }
else if (nodeType === 'EVENTSEND' || nodeType === 'EVENTLISTENE') { else if (nodeType === 'EVENTSEND' || nodeType === 'EVENTLISTENE') {
const { eventList } = store.getState().ideContainer; const { eventList } = store.getState().ideContainer;
@ -1067,26 +1051,10 @@ export const useFlowCallbacks = (
}; };
} }
else if (nodeType === 'SUB') { else if (nodeType === 'SUB') {
const flowSubMap = flowData[currentAppData.id]?.subMap || {}; newNode.data.component = {
const sameData: any = flowSubMap[newNode.data.compId]; type: nodeType,
if (sameData) { compId: newNode.data.compId
newNode.data.component = { };
type: nodeType,
compId: newNode.data.compId,
customDef: JSON.stringify({
dataIns: newNode.data.parameters.dataIns,
dataOuts: newNode.data.parameters.dataOuts,
subflowId: sameData,
name: newNode.data.title
})
};
}
else {
newNode.data.component = {
type: nodeType,
compId: newNode.data.compId
};
}
} }
else if (nodeType === 'EVENTSEND' || nodeType === 'EVENTLISTENE') { else if (nodeType === 'EVENTSEND' || nodeType === 'EVENTLISTENE') {
const { eventList } = store.getState().ideContainer; const { eventList } = store.getState().ideContainer;
@ -1181,22 +1149,15 @@ export const useFlowCallbacks = (
const res1: any = await queryEventItemBySceneIdOld(info.id); const res1: any = await queryEventItemBySceneIdOld(info.id);
if (res1.code === 200) dispatch(updateEventListOld(res1.data)); if (res1.code === 200) dispatch(updateEventListOld(res1.data));
// 更新缓存数据 - 与主流程保持一致 const appRes: any = await getAppInfoNew(currentAppData.parentAppId);
dispatch(updateCanvasDataMap({
...canvasDataMap,
[currentAppData.id]: { nodes, edges }
}));
const appRes: any = await getAppInfoNew(currentAppData.id);
// 更新 flowData 中的数据 // 更新 flowData 中的数据
dispatch(updateFlowData({ [currentAppData.id]: appRes.data })); dispatch(updateFlowData({ [currentAppData.parentAppId]: appRes.data }));
// 同步更新到 canvasDataMap // 同步更新到 canvasDataMap
if (appRes.data.main?.components) { if (appRes.data.main?.components) {
const { nodes, edges } = convertFlowData(appRes.data.main.components, true); const { nodes, edges } = convertFlowData(appRes.data.main.components, true);
setNodes(nodes);
setEdges(edges);
dispatch(updateCanvasDataMap({ dispatch(updateCanvasDataMap({
...canvasDataMap, ...canvasDataMap,
[currentAppData.id]: { nodes, edges } [currentAppData.parentAppId]: { nodes, edges }
})); }));
} }
} }
@ -1213,6 +1174,7 @@ export const useFlowCallbacks = (
appEventDefinition, appEventDefinition,
sceneId: info.id sceneId: info.id
}; };
const res: any = await setMainFlowNew(params, initialData.appId); const res: any = await setMainFlowNew(params, initialData.appId);
if (res.code === 200) { if (res.code === 200) {
Message.success('保存成功'); Message.success('保存成功');
@ -1328,6 +1290,7 @@ export const useFlowCallbacks = (
} }
} }
}, [nodes, edges, initialData?.appId]); }, [nodes, edges, initialData?.appId]);
// 运行处理函数 // 运行处理函数
const handleRun = useCallback(async (running: boolean) => { const handleRun = useCallback(async (running: boolean) => {
const { currentAppData, socketId, appRuntimeData } = store.getState().ideContainer; const { currentAppData, socketId, appRuntimeData } = store.getState().ideContainer;

@ -244,8 +244,10 @@ export const upDatePublish = async (revertedData) => {
publishAppId: [] publishAppId: []
}; };
revertedData.forEach(item => { revertedData.forEach(item => {
if (item?.component && item.component.type === 'SUB' && !item.component.customDef) params.publishAppId.push(item.component.compId); // 复合组件的这个compId实际上就是flowHousVO里面的id // 复合组件的这个compId实际上就是flowHousVO里面的id
if (item?.component && item.component.type === 'SUB' && !item.component.customDef) params.publishAppId.push(`${item.component.compId}/${item.nodeId}`);
}); });
if (params.publishAppId.length > 0) { if (params.publishAppId.length > 0) {
const res: any = await refPublish(params); const res: any = await refPublish(params);
if (res.code === 200) return res.data; if (res.code === 200) return res.data;

@ -120,13 +120,14 @@ function IDEContainer() {
// 监听自定义事件,处理打开子节点标签页的逻辑 // 监听自定义事件,处理打开子节点标签页的逻辑
useEffect(() => { useEffect(() => {
const handleOpenSubNodeTab = (event: CustomEvent) => { const handleOpenSubNodeTab = async (event: CustomEvent) => {
const { node } = event.detail; const { node } = event.detail;
const subCompList = flowData[currentAppData.id].subs; const subCompList = flowData[currentAppData.id].subs;
const customDef = isJSON(node.data.component.customDef) ? JSON.parse(node.data.component.customDef) : {}; const customDef = isJSON(node.data.component.customDef) ? JSON.parse(node.data.component.customDef) : {};
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) {
await getAppList();
const newNodeKey = currentSubComp.flowId; const newNodeKey = currentSubComp.flowId;
// 查找菜单项 // 查找菜单项

@ -516,7 +516,7 @@ export const revertFlowData = (nodes: any[], edges: any[]) => {
* React Flow nodes edges convertFlowData * React Flow nodes edges convertFlowData
* @param nodes - React Flow * @param nodes - React Flow
* @param edges - React Flow * @param edges - React Flow
* @param complexKV - 使id {IDsub_ID} * @param complexKV - 使id {ID/nodeIdsub_ID}
* @returns convertFlowData * @returns convertFlowData
*/ */
export const reverseConvertFlowData = (nodes: any[], edges: any[], complexKV: any) => { export const reverseConvertFlowData = (nodes: any[], edges: any[], complexKV: any) => {
@ -537,13 +537,28 @@ export const reverseConvertFlowData = (nodes: any[], edges: any[], complexKV: an
// 处理 component 信息 // 处理 component 信息
if (node.type === 'SUB' && !node.data.component.customDef) { if (node.type === 'SUB' && !node.data.component.customDef) {
let subflowId = '';
if (complexKV && node.data.compId) {
// 遍历complexKV找到匹配的条目使用节点ID进行匹配
for (const key in complexKV) {
if (key.includes('/')) {
const [numericId, nodeId] = key.split('/');
// 使用节点ID进行匹配
if (nodeId === node.id) {
subflowId = complexKV[key];
break;
}
}
}
}
nodeConfig.component = { nodeConfig.component = {
type: 'SUB', type: 'SUB',
compId: node.data.compId, compId: node.data.compId,
customDef: JSON.stringify({ customDef: JSON.stringify({
dataIns: node.data.parameters.dataIns, dataIns: node.data.parameters.dataIns,
dataOuts: node.data.parameters.dataOuts, dataOuts: node.data.parameters.dataOuts,
subflowId: complexKV[node.data.compId], subflowId: subflowId,
name: node.data.title name: node.data.title
}) })
}; };
@ -552,7 +567,9 @@ export const reverseConvertFlowData = (nodes: any[], edges: any[], complexKV: an
nodeConfig.component = { ...node.data.component }; nodeConfig.component = { ...node.data.component };
} }
else { else {
nodeConfig.component = null; nodeConfig.component = {
type: node.type
};
} }
// 处理参数信息 // 处理参数信息

Loading…
Cancel
Save