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

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