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) && (