From c86441727f60bc7a4651e39e91cfdc87d9095e0a Mon Sep 17 00:00:00 2001 From: ZLY Date: Thu, 30 Oct 2025 11:07:18 +0800 Subject: [PATCH] =?UTF-8?q?feat(flow):=20=E7=A6=81=E7=94=A8=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E7=BC=96=E6=8E=92=E6=A8=A1=E5=BC=8F=E4=B8=8B=E7=9A=84?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=92=8C=E4=B8=8A=E4=B8=8B=E6=96=87=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 isDeleteDisabled 状态以控制删除功能的可用性 - 在应用编排模式(useDefault为 false)下禁用节点删除- 在应用编排模式或运行时状态下禁用节点/边/画布上下文菜单 - 更新 onNodeContextMenu、onEdgeContextMenu 和 onPaneContextMenu 的条件判断 -限制统一添加节点菜单仅在默认模式且非运行时显示 - 在 deleteNode 和 deleteEdge 回调中增加 useDefault 状态检查 - 更新相关依赖数组以包含 useDefault 状态变化监听 --- src/hooks/useFlowCallbacks.ts | 16 +++++++++++-- src/pages/flowEditor/FlowEditorMain.tsx | 32 +++++++++++++++---------- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/hooks/useFlowCallbacks.ts b/src/hooks/useFlowCallbacks.ts index 3da3910..69e247b 100644 --- a/src/hooks/useFlowCallbacks.ts +++ b/src/hooks/useFlowCallbacks.ts @@ -559,6 +559,12 @@ export const useFlowCallbacks = ( // region 节点/边操作 // 删除节点函数 const deleteNode = useCallback((node: Node) => { + // 在应用编排模式下(useDefault为false)不允许删除节点 + if (!useDefault) { + console.warn('在应用编排模式下不允许删除节点'); + return; + } + // 开始和结束节点不允许删除 if (node.type === 'start' || node.type === 'end') { console.warn('开始和结束节点不允许删除'); @@ -646,9 +652,15 @@ export const useFlowCallbacks = ( }); document.dispatchEvent(event); }, 0); - }, [nodes, edges]); + }, [nodes, edges, useDefault]); // 删除边函数 const deleteEdge = useCallback((edge: Edge) => { + // 在应用编排模式下(useDefault为false)不允许删除边 + if (!useDefault) { + console.warn('在应用编排模式下不允许删除边'); + return; + } + setEdges((eds: Edge[]) => eds.filter((e) => e.id !== edge.id)); // 删除边后记录历史 @@ -661,7 +673,7 @@ export const useFlowCallbacks = ( }); document.dispatchEvent(event); }, 0); - }, [nodes, edges]); + }, [nodes, edges, useDefault]); // 在边上添加节点的具体实现 const addNodeOnEdge = useCallback((nodeType: string, node: any) => { const { currentAppData, flowData } = store.getState().ideContainer; diff --git a/src/pages/flowEditor/FlowEditorMain.tsx b/src/pages/flowEditor/FlowEditorMain.tsx index e1d3eb4..2e73581 100644 --- a/src/pages/flowEditor/FlowEditorMain.tsx +++ b/src/pages/flowEditor/FlowEditorMain.tsx @@ -145,6 +145,9 @@ const FlowEditorMain: React.FC = (props) => { ? appRuntimeData[currentAppData.id].isRunning : false; + // 在应用编排模式下(useDefault为false)禁用删除功能 + const isDeleteDisabled = !useDefault || currentAppIsRunning; + // 监听键盘事件实现快捷键 useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { @@ -210,9 +213,14 @@ const FlowEditorMain: React.FC = (props) => { ); // 允许删除操作继续进行 - return !currentAppIsRunning; // 运行时禁止删除节点 + return !isDeleteDisabled; // 在应用编排模式或运行时禁止删除节点 }} onNodesDelete={(deleted) => { + // 如果在应用编排模式或运行时,禁止删除 + if (isDeleteDisabled) { + return; + } + // 检查是否有循环节点 const loopNodes = deleted.filter(node => node.data?.type === 'LOOP_START' || node.data?.type === 'LOOP_END' @@ -279,11 +287,11 @@ const FlowEditorMain: React.FC = (props) => { connectionLineType={ConnectionLineType.SmoothStep} connectionLineComponent={CustomConnectionLine} onNodeDragStop={!currentAppIsRunning ? onNodeDragStop : undefined} // 运行时禁用节点拖拽停止 - onNodeContextMenu={!currentAppIsRunning ? onNodeContextMenu : undefined} // 运行时禁用节点上下文菜单 + onNodeContextMenu={(!currentAppIsRunning && useDefault) ? onNodeContextMenu : undefined} // 运行时或应用编排模式下禁用节点上下文菜单 onNodeDoubleClick={!currentAppIsRunning ? onNodeDoubleClick : undefined} // 运行时禁用节点双击 - onEdgeContextMenu={!currentAppIsRunning ? onEdgeContextMenu : undefined} // 运行时禁用边上下文菜单 + onEdgeContextMenu={(!currentAppIsRunning && useDefault) ? onEdgeContextMenu : undefined} // 运行时或应用编排模式下禁用边上下文菜单 onPaneClick={!currentAppIsRunning ? onPaneClick : undefined} // 运行时禁用面板点击 - onPaneContextMenu={!currentAppIsRunning ? onPaneContextMenu : undefined} // 运行时禁用面板上下文菜单 + onPaneContextMenu={(!currentAppIsRunning && useDefault) ? onPaneContextMenu : undefined} // 运行时或应用编排模式下禁用面板上下文菜单 onEdgeMouseEnter={(_event, edge) => { setEdges((eds) => eds.map(e => { if (e.id === edge.id) { @@ -320,8 +328,8 @@ const FlowEditorMain: React.FC = (props) => { - {/*节点右键上下文*/} - {!currentAppIsRunning && menu && menu.type === 'node' && ( + {/*节点右键上下文 - 仅在默认模式且非运行时显示*/} + {!currentAppIsRunning && useDefault && menu && menu.type === 'node' && (
= (props) => {
)} - {/*边右键上下文*/} - {!currentAppIsRunning && menu && menu.type === 'edge' && ( + {/*边右键上下文 - 仅在默认模式且非运行时显示*/} + {!currentAppIsRunning && useDefault && menu && menu.type === 'edge' && (
= (props) => {
)} - {/*画布右键上下文*/} - {!currentAppIsRunning && menu && menu.type === 'pane' && ( + {/*画布右键上下文 - 仅在默认模式且非运行时显示*/} + {!currentAppIsRunning && useDefault && menu && menu.type === 'pane' && (
= (props) => { onClose={closeEditModal} /> - {/*统一的添加节点菜单*/} - {!currentAppIsRunning && (edgeForNodeAdd || positionForNodeAdd) && ( + {/*统一的添加节点菜单 - 仅在默认模式且非运行时显示*/} + {!currentAppIsRunning && useDefault && (edgeForNodeAdd || positionForNodeAdd) && (