优化节点超时节点卡顿问题

pull/710/head
Lemon 2025-02-24 17:00:05 +08:00
parent 4b96a6458b
commit da7c9e9796
1 changed files with 34 additions and 30 deletions

View File

@ -165,53 +165,57 @@ const nodeClick = () => {
const deleteNode = () => { const deleteNode = () => {
emits('update:flowNode', currentNode.value.childNode) emits('update:flowNode', currentNode.value.childNode)
} }
// 查找可以驳回用户节点 // 优化后的查找可驳回用户节点函数
const findReturnTaskNodes = ( const findReturnTaskNodes = (matchNodeList: SimpleFlowNode[]) => {
matchNodeList: SimpleFlowNode[] // 匹配的节点 // 创建 Set 用于去重,提前初始化以避免重复操作
) => { const uniqueNodes = new Set<SimpleFlowNode>()
// 从父节点查找所有用户任务节点 const currentNodeId = currentNode.value.id
// 从父节点查找用户任务节点
emits('find:parentNode', matchNodeList, NodeType.USER_TASK_NODE) emits('find:parentNode', matchNodeList, NodeType.USER_TASK_NODE)
// 递归查找当前节点的子节点 // 先将父节点中的有效节点添加到 Set
findChildUserTaskNodes(currentNode.value, matchNodeList)
// 过滤掉当前节点和重复节点
const currentNodeId = currentNode.value.id
// 使用 Map 来去重,以节点 id 为 key
const uniqueNodes = new Map()
matchNodeList.forEach(node => { matchNodeList.forEach(node => {
if (node.id !== currentNodeId) { if (node.id !== currentNodeId) {
uniqueNodes.set(node.id, node) uniqueNodes.add(node)
} }
}) })
// 清空原数组并添加去重后的节点 // 查找子节点并直接添加到 Set
findChildUserTaskNodes(currentNode.value, uniqueNodes, currentNodeId)
// 直接用 Set 的值更新数组
matchNodeList.length = 0 matchNodeList.length = 0
matchNodeList.push(...Array.from(uniqueNodes.values())) matchNodeList.push(...uniqueNodes)
} }
// 递归查找子节点中的用户任务节点 // 优化后的子节点查找函数
const findChildUserTaskNodes = (node: SimpleFlowNode, matchNodeList: SimpleFlowNode[]) => { const findChildUserTaskNodes = (
node: SimpleFlowNode,
uniqueNodes: Set<SimpleFlowNode>,
currentNodeId: string
) => {
if (!node) return if (!node) return
// 检查子节点 // 处理直接子节点
if (node.childNode) { if (node.childNode) {
if (node.childNode.type === NodeType.USER_TASK_NODE) { if (node.childNode.type === NodeType.USER_TASK_NODE && node.childNode.id !== currentNodeId) {
matchNodeList.push(node.childNode) uniqueNodes.add(node.childNode)
} }
findChildUserTaskNodes(node.childNode, matchNodeList) findChildUserTaskNodes(node.childNode, uniqueNodes, currentNodeId)
} }
// 检查条件分支节点 // 处理条件分支节点
if (node.type === NodeType.CONDITION_BRANCH_NODE && node.conditionNodes) { if (node.type === NodeType.CONDITION_BRANCH_NODE && node.conditionNodes) {
node.conditionNodes.forEach(conditionNode => { for (const conditionNode of node.conditionNodes) {
if (conditionNode.childNode) { if (conditionNode.childNode) {
if (conditionNode.childNode.type === NodeType.USER_TASK_NODE) { if (conditionNode.childNode.type === NodeType.USER_TASK_NODE &&
matchNodeList.push(conditionNode.childNode) conditionNode.childNode.id !== currentNodeId) {
uniqueNodes.add(conditionNode.childNode)
} }
findChildUserTaskNodes(conditionNode.childNode, matchNodeList) findChildUserTaskNodes(conditionNode.childNode, uniqueNodes, currentNodeId)
} }
}) }
} }
} }