feat: 工作流增加条件判断节点,重构部分UI

This commit is contained in:
2026-03-04 17:35:49 +08:00
parent 67d42a80b9
commit 27376a5f33
14 changed files with 2481 additions and 31 deletions

View File

@@ -3,7 +3,6 @@
Background,
Controls,
type Edge,
type Handle,
MarkerType,
MiniMap,
type Node,
@@ -33,14 +32,14 @@
import {onDestroy, onMount} from 'svelte';
import {isInEditableElement} from '#components/utils/isInEditableElement';
const { onInit, ...rest } = $props();
const { onInit }: { onInit: any; [key: string]: any } = $props();
const svelteFlow = useSvelteFlow();
console.log('props', rest);
onInit(svelteFlow);
let showEdgePanel = $state(false);
let currentEdge = $state<Edge | null>(null);
const asString = (value: unknown) => (value == null ? '' : String(value));
const { updateEdgeData } = useUpdateEdgeData();
@@ -122,7 +121,7 @@
}
const fromNode = state.fromNode as Node;
const fromHande = state.fromHandle as Handle;
const fromHande = state.fromHandle as any;
const newNode = {
position: { ...toNode.position }
@@ -338,7 +337,31 @@
showEdgePanel = true;
currentEdge = e.edge;
}}
onbeforeconnect={(edge) => {
onbeforeconnect={(edge: any) => {
const sourceNode = edge.source ? getNode(edge.source) : null;
const sourceHandle = edge.sourceHandle || '';
const isConditionBranchEdge = sourceNode?.type === 'conditionNode'
&& typeof sourceHandle === 'string'
&& sourceHandle.startsWith('branch_');
if (isConditionBranchEdge) {
const branchId = sourceHandle.slice(7);
const branches = (sourceNode?.data?.branches || []) as Array<any>;
const branch = branches.find((item) => item?.id === branchId);
const branchLabel = branch?.label || '条件分支';
return {
...edge,
id: genShortId(),
data: {
...((edge as any).data || {}),
managedByConditionNode: true,
branchId,
branchLabel,
condition: `matchedBranchId === '${branchId}'`
}
};
}
return {
...edge,
id:genShortId(),
@@ -376,24 +399,43 @@
<div>边属性设置</div>
<div class="setting-title">边条件设置</div>
<div class="setting-item">
<Textarea
rows={3}
placeholder="请输入边条件"
style="width: 100%"
value={currentEdge?.data?.condition}
onchange={(e)=>{
if (currentEdge){
updateEdgeData(currentEdge.id, {
condition: e.target?.value
})
}
}}
/>
{#if currentEdge?.data?.managedByConditionNode}
<div class="readonly-edge-settings">
<div class="readonly-edge-branch">
分支:{currentEdge?.data?.branchLabel || currentEdge?.data?.branchId || '-'}
</div>
<Textarea
rows={3}
style="width: 100%"
disabled={true}
value={asString(currentEdge?.data?.condition)}
/>
<div class="readonly-edge-tip">
该连线由条件节点托管,条件表达式不可在边面板手动修改。
</div>
</div>
{:else}
<Textarea
rows={3}
placeholder="请输入边条件"
style="width: 100%"
value={asString(currentEdge?.data?.condition)}
onchange={(e)=>{
if (currentEdge){
updateEdgeData(currentEdge.id, {
condition: (e.target as HTMLTextAreaElement)?.value || ''
})
}
}}
/>
{/if}
</div>
<div class="setting-item" style="padding: 8px 0">
<Button
onclick={() => {
deleteEdge(currentEdge?.id)
if (currentEdge?.id) {
deleteEdge(currentEdge.id)
}
showEdgePanel = false;
}}
>
@@ -438,4 +480,20 @@
align-items: center;
justify-content: end;
}
.readonly-edge-settings {
width: 100%;
}
.readonly-edge-branch {
font-size: 12px;
color: #6b7280;
margin-bottom: 8px;
}
.readonly-edge-tip {
margin-top: 6px;
font-size: 12px;
color: #9ca3af;
}
</style>