diff --git a/src/pages/Setting/Flow/X6ActionContext.ts b/src/pages/Setting/Flow/X6ActionContext.ts index 55afd965fe58923f7cf327f6fb82f52edb8e9c4f..1698c90467d139a7d94459c808be35353d51acf6 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 7dcfde20e05be4b88b9e2a7fb008b3cb35be6c26..0cf088a1f98f1a9db650ba682995566278a0b05b 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 ba523f15f5a4bfc33d7305cba1bce54440fc7aba..95a3f36ba592cac38b544cc7969546d2ddf91162 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 (