feat(flow-editor): 多出口泳道 UI(抽屉开关+出口路由容器+分支增删/恢复单出口)
This commit is contained in:
@@ -25,6 +25,7 @@ import {
|
||||
createEmptyModel,
|
||||
createNotify,
|
||||
createParallel,
|
||||
branchesOf,
|
||||
findItem,
|
||||
removeItem,
|
||||
resolveContainer,
|
||||
@@ -521,7 +522,7 @@ function insertItem(container: string, index: number, kind: "approval" | "parall
|
||||
}
|
||||
}
|
||||
|
||||
/** 添加分支(并行/条件分支容器通用;条件分支同步补一个占位出口名) */
|
||||
/** 添加分支(并行/条件分支/多出口审批容器通用;条件分支与出口同步补一个占位出口名) */
|
||||
function addBranch(containerUid: string): void {
|
||||
const item = findItem(model, containerUid);
|
||||
if (!item) return;
|
||||
@@ -531,18 +532,42 @@ function addBranch(containerUid: string): void {
|
||||
const no = item.branches.length + 1;
|
||||
item.branches.push([createApproval()]);
|
||||
item.outlets.push(`出口${["一", "二", "三", "四", "五", "六"][no - 1] || no}`);
|
||||
} else if (item.kind === "approval" && item.outlets && item.outlets.length >= 2) {
|
||||
const no = (item.branches?.length || 0) + 1;
|
||||
(item.branches = item.branches || []).push([createApproval()]);
|
||||
item.outlets.push(`出口${["一", "二", "三", "四", "五", "六"][no - 1] || no}`);
|
||||
}
|
||||
}
|
||||
|
||||
function removeBranch(containerUid: string, index: number): void {
|
||||
const item = findItem(model, containerUid);
|
||||
if (!item || (item.kind !== "parallel" && item.kind !== "condition")) return;
|
||||
if (item.branches.length <= 2) {
|
||||
const isOutlet = item.kind === "approval" && !!(item.outlets && item.outlets.length >= 2);
|
||||
if (!item || (item.kind !== "parallel" && item.kind !== "condition" && !isOutlet)) return;
|
||||
const branches = item.branches!;
|
||||
if (branches.length <= 2) {
|
||||
Message.warning("分支至少保留 2 个");
|
||||
return;
|
||||
}
|
||||
item.branches.splice(index, 1);
|
||||
if (item.kind === "condition") item.outlets.splice(index, 1);
|
||||
branches.splice(index, 1);
|
||||
if (item.kind === "condition" || isOutlet) item.outlets!.splice(index, 1);
|
||||
}
|
||||
|
||||
/** 退出多出口:仅保留出口①泳道内容,替换为「本节点(去 outlets) + ①泳道节点序列」 */
|
||||
function exitOutlets(uid: string): void {
|
||||
const rec = (items: EditorItem[]): boolean => {
|
||||
const i = items.findIndex((it) => it.uid === uid);
|
||||
if (i >= 0) {
|
||||
const node = items[i] as ApprovalNode;
|
||||
const lane0 = node.branches?.[0] || [];
|
||||
const clean: ApprovalNode = { ...node };
|
||||
delete clean.outlets;
|
||||
delete clean.branches;
|
||||
items.splice(i, 1, clean, ...lane0);
|
||||
return true;
|
||||
}
|
||||
return items.some((it) => branchesOf(it)?.some((b) => rec(b)) || false);
|
||||
};
|
||||
rec(model.list);
|
||||
}
|
||||
|
||||
provide<EditorCtx>(EDITOR_CTX, {
|
||||
@@ -556,6 +581,7 @@ provide<EditorCtx>(EDITOR_CTX, {
|
||||
insertItem,
|
||||
addBranch,
|
||||
removeBranch,
|
||||
exitOutlets,
|
||||
});
|
||||
|
||||
// ==================== 保存 / 离开 ====================
|
||||
|
||||
Reference in New Issue
Block a user