卡顿问题
parent
9b04918118
commit
5e3d89e279
|
|
@ -144,50 +144,49 @@ const findFromParentNode = (nodeList: SimpleFlowNode[], nodeType: number) => {
|
|||
const nodeCache = new Map<string, SimpleFlowNode[]>()
|
||||
|
||||
const recursiveFindParentNode = (
|
||||
nodeList: SimpleFlowNode[],
|
||||
findNode: SimpleFlowNode,
|
||||
nodeType: number
|
||||
nodeList: SimpleFlowNode[],
|
||||
findNode: SimpleFlowNode,
|
||||
nodeType: number
|
||||
) => {
|
||||
if (!findNode) return
|
||||
|
||||
// 检查缓存
|
||||
const cacheKey = `${findNode.id}-${nodeType}`
|
||||
if (nodeCache.has(cacheKey)) {
|
||||
const cachedNodes = nodeCache.get(cacheKey)
|
||||
nodeList.push(...cachedNodes!)
|
||||
return
|
||||
}
|
||||
|
||||
const foundNodes: SimpleFlowNode[] = []
|
||||
|
||||
// 检查当前节点
|
||||
if (findNode.type === nodeType) {
|
||||
foundNodes.push(findNode)
|
||||
}
|
||||
|
||||
// 检查子节点
|
||||
if (findNode.childNode) {
|
||||
if (findNode.childNode.type === nodeType) {
|
||||
foundNodes.push(findNode.childNode)
|
||||
}
|
||||
recursiveFindParentNode(foundNodes, findNode.childNode, nodeType)
|
||||
}
|
||||
|
||||
// 检查条件分支节点
|
||||
if (findNode.type === NodeType.CONDITION_BRANCH_NODE && findNode.conditionNodes) {
|
||||
findNode.conditionNodes.forEach(conditionNode => {
|
||||
if (conditionNode.childNode) {
|
||||
recursiveFindParentNode(foundNodes, conditionNode.childNode, nodeType)
|
||||
|
||||
// Create a Set to track visited nodes and prevent cycles
|
||||
const visitedNodes = new Set<string>()
|
||||
|
||||
const findNodesRecursive = (node: SimpleFlowNode) => {
|
||||
if (!node || visitedNodes.has(node.id)) return
|
||||
|
||||
visitedNodes.add(node.id)
|
||||
|
||||
// Check current node
|
||||
if (node.type === nodeType) {
|
||||
if (!nodeList.some(n => n.id === node.id)) {
|
||||
nodeList.push(node)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Check child node
|
||||
if (node.childNode) {
|
||||
findNodesRecursive(node.childNode)
|
||||
}
|
||||
|
||||
// Check condition nodes if present
|
||||
if (node.type === NodeType.CONDITION_BRANCH_NODE && node.conditionNodes) {
|
||||
node.conditionNodes.forEach(conditionNode => {
|
||||
if (conditionNode.childNode) {
|
||||
findNodesRecursive(conditionNode.childNode)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 存入缓存
|
||||
nodeCache.set(cacheKey, foundNodes)
|
||||
nodeList.push(...foundNodes)
|
||||
// Start recursive search
|
||||
findNodesRecursive(findNode)
|
||||
|
||||
// 继续向上递归查找
|
||||
emits('find:recursiveFindParentNode', nodeList, props.parentNode, nodeType)
|
||||
// Continue search in parent node
|
||||
if (props.parentNode) {
|
||||
emits('find:recursiveFindParentNode', nodeList, props.parentNode, nodeType)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style lang="scss" scoped></style>
|
||||
|
|
|
|||
Loading…
Reference in New Issue