From 532683c73ce01a04059b5b25447098d9253cc3f5 Mon Sep 17 00:00:00 2001 From: yms Date: Tue, 18 Mar 2025 17:57:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Setting/Flow/X6ActionContext.ts | 3 +- src/pages/Setting/Flow/index.tsx | 81 +++++++++++-------- src/pages/Setting/Flow/nodes/conditionBtn.tsx | 7 +- src/pages/Setting/Flow/nodes/gateway.tsx | 12 ++- 4 files changed, 60 insertions(+), 43 deletions(-) diff --git a/src/pages/Setting/Flow/X6ActionContext.ts b/src/pages/Setting/Flow/X6ActionContext.ts index 55afd96..1698c90 100644 --- a/src/pages/Setting/Flow/X6ActionContext.ts +++ b/src/pages/Setting/Flow/X6ActionContext.ts @@ -1,7 +1,8 @@ +import { Node } from "@antv/x6"; import React from "react"; const X6ActionContext = React.createContext<{ - addCondition?: (id: string, base?: boolean) => void; + addCondition?: (node: Node) => void; openSetting?: (id: string) => void; actionNode?: any; onDelete?: (id: string) => void; diff --git a/src/pages/Setting/Flow/index.tsx b/src/pages/Setting/Flow/index.tsx index 7dcfde2..0cf088a 100644 --- a/src/pages/Setting/Flow/index.tsx +++ b/src/pages/Setting/Flow/index.tsx @@ -321,6 +321,7 @@ const Flow = () => { data: { type: "addConditionBtn", pid: source.id, + target: target, }, }; @@ -346,10 +347,10 @@ const Flow = () => { cloneX6Data = cloneX6Data.map((v) => { if (v.id === target.id) { - v.data.pid = v.data.pid?.replace(source.id, conditionsNodeData.id); - } - if (v.id === "endEvent") { - v.data.pid = v.data.pid + "," + condition1.id; + v.data.pid = v.data.pid?.replace( + source.id, + `${conditionsNodeData.id},${condition1.id}` + ); } return v; }); @@ -379,6 +380,8 @@ const Flow = () => { data: { type: "addConditionBtn", pid: source.id, + //** 保存最初的目的地 */ + target: target, base: true, }, }; @@ -406,10 +409,10 @@ const Flow = () => { cloneX6Data = cloneX6Data.map((v) => { if (v.id === target.id) { - v.data.pid = v.data.pid?.replace(source.id, conditionsNodeData.id); - } - if (v.id === "endEvent") { - v.data.pid = v.data.pid + "," + condition1.id; + v.data.pid = v.data.pid?.replace( + source.id, + `${conditionsNodeData.id},${condition1.id}` + ); } return v; }); @@ -546,24 +549,32 @@ const Flow = () => { }); }; /** @description 增加条件节点 */ - const addCondition = (nodeId: string, base = false) => { + const addCondition = (node: Node) => { + const { base, target } = node.getData(); + + if (!target?.id) { + notification.warning({ + message: "老版本流程图已不在维护!", + }); + return; + } const nodeData = getDefaultNodeByType(base ? 7 : 4); let cloneX6Data = cloneDeep(originalXNodesData.current); const childrenNum = cloneX6Data.filter( - (v) => v.data.pid === nodeId + (v) => v.data.pid === node.id )?.length; const condition: Node.Metadata = { id: nodeData.elementId, shape: base ? "custom-base-condition-node" : "custom-condition-node", data: { ...nodeData, - pid: nodeId, + pid: node?.id, elementAlias: "条件" + childrenNum, conditionType: childrenNum, }, }; cloneX6Data = cloneX6Data.map((v) => { - if (v.id === "endEvent") { + if (v.id === target?.id) { v.data.pid = v.data.pid + "," + condition.id; } return v; @@ -575,7 +586,6 @@ const Flow = () => { /** @description 删除节点 */ const onDelete = (nodeId: string) => { - console.log("onDelete", nodeId); let cloneX6Data = cloneDeep(originalXNodesData.current); const nodeMap = NodeMap(cloneX6Data); @@ -593,23 +603,27 @@ const Flow = () => { const delNodePid = cloneX6Data.find((v) => v.id === id)?.data.pid; cloneX6Data = cloneX6Data.filter((v) => v.id !== id); const childNodes = nodeMap.childMap.get(id) ?? []; - for (let childNode of childNodes) { - let child = cloneX6Data.find((v) => v.id === childNode.id); + childNodes.forEach((childNode) => { + const child = cloneX6Data.find((v) => v.id === childNode.id); child!.data.pid = replacePids(child!.data.pid, id, delNodePid); - } + }); }; /** 不考虑替换id,彻底的链式删除 */ - const linksDelete = (id: string) => { - if (id === "endEvent") { - return; - } + const linksDelete = (id: string, endId: string) => { cloneX6Data = cloneX6Data.filter((v) => v.id !== id); const childNodes = nodeMap.childMap.get(id) ?? []; - for (let childNode of childNodes) { - let child = cloneX6Data.find((v) => v.id === childNode.id); - child!.data.pid = delPid(child!.data.pid, id); - linksDelete(childNode.id); - } + + childNodes.forEach((v) => { + if (v.id !== endId) { + linksDelete(v.id, endId); + } + if (v.id === endId) { + cloneX6Data.find((v) => v.id === endId)!.data.pid = delPid( + v.data.pid, + id + ); + } + }); }; /** 删除审批节点 */ @@ -621,19 +635,20 @@ const Flow = () => { if (nodeType === 4 || nodeType === 7) { const childNodes = nodeMap.childMap.get(pid) ?? []; + const pNode = nodeMap.nodeMap.get(pid); + if (childNodes.length > 2) { - linksDelete(nodeId); + linksDelete(nodeId, pNode.data?.target.id); } else { - // linksDelete(nodeId); deleteById(pid); + const pchild = nodeMap.childMap.get(pid); + pchild?.forEach((v) => { + deleteById(v.id); + }); - for (let childNode of childNodes) { - deleteById(childNode.id); + if (pNode.data?.target.id) { + linksDelete(nodeId, pNode.data?.target.id); } - - linksDelete(nodeId); - // if(pid !===) - // cloneX6Data.find(v=>v.data.id === 'endEvent')?.pid = delPid() } } diff --git a/src/pages/Setting/Flow/nodes/conditionBtn.tsx b/src/pages/Setting/Flow/nodes/conditionBtn.tsx index ba523f1..95a3f36 100644 --- a/src/pages/Setting/Flow/nodes/conditionBtn.tsx +++ b/src/pages/Setting/Flow/nodes/conditionBtn.tsx @@ -5,17 +5,12 @@ import { Node } from "@antv/x6"; const ConditionBtn = ({ node }: { node: Node }) => { const { addCondition } = useContext(X6ActionContext); - const id = node.id; return (
{ - if (node.getData().base) { - addCondition!(id, true); - return; - } - addCondition!(id); + addCondition!(node); }} > 添加条件 diff --git a/src/pages/Setting/Flow/nodes/gateway.tsx b/src/pages/Setting/Flow/nodes/gateway.tsx index c4feb23..fcd56f2 100644 --- a/src/pages/Setting/Flow/nodes/gateway.tsx +++ b/src/pages/Setting/Flow/nodes/gateway.tsx @@ -45,9 +45,15 @@ const GatewayNode = (props: GatewayNodeProps) => { - + {edgeData.source.data.nodeType !== 4 && + edgeData.source.data.nodeType !== 7 && ( + + )} {edgeData.source.id === "startEvent" && (