feat(flowEditor):优化删除逻辑和边操作权限控制

master
钟良源 3 months ago
parent cfd9cd3cc4
commit 615d6ebe4e

@ -693,9 +693,15 @@ export const useFlowCallbacks = (
}, [nodes, edges, useDefault]);
// 删除边函数
const deleteEdge = useCallback((edge: Edge) => {
// 在应用编排模式下useDefault为false不允许删除边
if (!useDefault) {
console.warn('在应用编排模式下不允许删除边');
// 获取当前应用的运行状态
const { appRuntimeData, currentAppData } = store.getState().ideContainer;
const currentAppIsRunning = currentAppData?.id && appRuntimeData[currentAppData.id]
? appRuntimeData[currentAppData.id].isRunning
: false;
// 在运行时禁止删除边
if (currentAppIsRunning) {
console.warn('在运行时不允许删除边');
return;
}
@ -711,7 +717,7 @@ export const useFlowCallbacks = (
});
document.dispatchEvent(event);
}, 0);
}, [nodes, edges, useDefault]);
}, [nodes, edges]);
// 在边上添加节点的具体实现
const addNodeOnEdge = useCallback((nodeType: string, node: any) => {
const { currentAppData, flowData } = store.getState().ideContainer;
@ -1294,7 +1300,7 @@ export const useFlowCallbacks = (
eventId: Array.from(new Set(item.eventId))
}));
try {
updateAppFlowData(appFlowParams);
updateAppFlowData(appEventParams);
if (appEventParams.length > 0) {
for (const item of appEventParams) {
await sleep(500);

@ -146,7 +146,7 @@ const FlowEditorMain: React.FC<FlowEditorMainProps> = (props) => {
: false;
// 在应用编排模式下useDefault为false禁用删除功能
const isDeleteDisabled = !useDefault || currentAppIsRunning;
const isDeleteDisabled = currentAppIsRunning;
// 监听键盘事件实现快捷键
useEffect(() => {
@ -199,7 +199,13 @@ const FlowEditorMain: React.FC<FlowEditorMainProps> = (props) => {
elementsSelectable={!currentAppIsRunning} // 运行时禁用元素选择
connectOnClick={!currentAppIsRunning} // 运行时禁用点击连接
disableKeyboardA11y={currentAppIsRunning} // 运行时禁用键盘交互
onBeforeDelete={async ({ nodes }) => {
onBeforeDelete={async ({ nodes, edges }) => {
// 在应用编排模式下useDefault为false只允许删除边不允许删除节点
if (!useDefault && nodes.length > 0) {
console.warn('在应用编排模式下不允许删除节点');
return false; // 阻止删除节点操作
}
// 检查是否有开始或结束节点
const hasStartOrEndNode = nodes.some(node => node.type === 'start' || node.type === 'end');
if (hasStartOrEndNode) {
@ -213,11 +219,17 @@ const FlowEditorMain: React.FC<FlowEditorMainProps> = (props) => {
);
// 允许删除操作继续进行
return !isDeleteDisabled; // 在应用编排模式或运行时禁止删除节点
return !currentAppIsRunning; // 在运行时禁止删除任何元素
}}
onNodesDelete={(deleted) => {
// 如果在应用编排模式或运行时,禁止删除
if (isDeleteDisabled) {
// 在应用编排模式下useDefault为false不允许删除节点
if (!useDefault) {
console.warn('在应用编排模式下不允许删除节点');
return;
}
// 如果在运行时,禁止删除
if (currentAppIsRunning) {
return;
}
@ -349,8 +361,8 @@ const FlowEditorMain: React.FC<FlowEditorMainProps> = (props) => {
</div>
)}
{/*边右键上下文 - 默认模式且非运行时显示*/}
{!currentAppIsRunning && useDefault && menu && menu.type === 'edge' && (
{/*边右键上下文 - 在非运行时显示,应用编排模式下也允许*/}
{!currentAppIsRunning && menu && menu.type === 'edge' && (
<div
style={{
position: 'absolute',

Loading…
Cancel
Save