优化审核节点流程节点多 打开审核节点卡顿问题

pull/710/head
Lemon 2025-02-25 15:06:38 +08:00
parent da7c9e9796
commit dc84312542
2 changed files with 79 additions and 33 deletions

View File

@ -54,8 +54,8 @@
:flow-node="currentNode"
@update:flow-node="handleModelValueUpdate"
/>
<!-- 触发器节点 -->
<TriggerNode
<!-- 触发器节点 -->
<TriggerNode
v-if="currentNode && currentNode.type === NodeType.TRIGGER_NODE"
:flow-node="currentNode"
@update:flow-node="handleModelValueUpdate"
@ -75,6 +75,7 @@
/>
</template>
<script setup lang="ts">
//
import StartUserNode from './nodes/StartUserNode.vue'
import EndEventNode from './nodes/EndEventNode.vue'
import UserTaskNode from './nodes/UserTaskNode.vue'
@ -85,72 +86,102 @@ import InclusiveNode from './nodes/InclusiveNode.vue'
import DelayTimerNode from './nodes/DelayTimerNode.vue'
import RouterNode from './nodes/RouterNode.vue'
import TriggerNode from './nodes/TriggerNode.vue'
//
import { SimpleFlowNode, NodeType } from './consts'
import { useWatchNode } from './node'
//
defineOptions({
name: 'ProcessNodeTree'
})
// props
const props = defineProps({
//
parentNode: {
type: Object as () => SimpleFlowNode,
default: () => null
},
//
flowNode: {
type: Object as () => SimpleFlowNode,
default: () => null
}
})
//
const emits = defineEmits<{
//
'update:flowNode': [node: SimpleFlowNode | undefined]
//
'find:recursiveFindParentNode': [
nodeList: SimpleFlowNode[],
curentNode: SimpleFlowNode,
nodeType: number
nodeList: SimpleFlowNode[], //
curentNode: SimpleFlowNode, //
nodeType: number //
]
}>()
// 使 useWatchNode hook
const currentNode = useWatchNode(props)
//
//
const handleModelValueUpdate = (updateValue) => {
emits('update:flowNode', updateValue)
}
//
const findFromParentNode = (nodeList: SimpleFlowNode[], nodeType: number) => {
emits('find:recursiveFindParentNode', nodeList, props.parentNode, nodeType)
}
//
//
const nodeCache = new Map<string, SimpleFlowNode[]>()
const recursiveFindParentNode = (
nodeList: SimpleFlowNode[],
findNode: SimpleFlowNode,
nodeType: number
) => {
if (!findNode) {
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) {
nodeList.push(findNode)
foundNodes.push(findNode)
}
//
if (findNode.childNode) {
if (findNode.childNode.type === nodeType) {
nodeList.push(findNode.childNode)
foundNodes.push(findNode.childNode)
}
recursiveFindParentNode(nodeList, findNode.childNode, nodeType)
recursiveFindParentNode(foundNodes, findNode.childNode, nodeType)
}
//
if (findNode.type === NodeType.CONDITION_BRANCH_NODE && findNode.conditionNodes) {
findNode.conditionNodes.forEach(conditionNode => {
if (conditionNode.childNode) {
recursiveFindParentNode(nodeList, conditionNode.childNode, nodeType)
recursiveFindParentNode(foundNodes, conditionNode.childNode, nodeType)
}
})
}
//
nodeCache.set(cacheKey, foundNodes)
nodeList.push(...foundNodes)
//
emits('find:recursiveFindParentNode', nodeList, props.parentNode, nodeType)
}
</script>

View File

@ -41,7 +41,7 @@
</div>
<div v-if="!readonly" class="node-toolbar">
<div class="toolbar-icon"
><Icon color="#0089ff" icon="ep:circle-close-filled" :size="18" @click="deleteNode"
><Icon color="#0089ff" icon="ep:circle-close-filled" :size="18" @click="deleteNode"
/></div>
</div>
</div>
@ -147,12 +147,16 @@ const nodeSetting = ref()
const nodeClick = () => {
if (readonly) {
console.log('[UserTaskNode] 开始处理只读模式点击, tasks长度:', tasks.value?.length)
if (tasks && tasks.value) {
dialogTitle.value = currentNode.value.name
console.time('过滤任务耗时')
//
selectTasks.value = tasks.value.filter(
(item: any) => item?.taskDefinitionKey === currentNode.value.id
)
console.timeEnd('过滤任务耗时')
console.log('[UserTaskNode] 过滤后的任务数:', selectTasks.value.length)
dialogVisible.value = true
}
} else {
@ -165,55 +169,66 @@ const nodeClick = () => {
const deleteNode = () => {
emits('update:flowNode', currentNode.value.childNode)
}
//
//
const findReturnTaskNodes = (matchNodeList: SimpleFlowNode[]) => {
// Set ,
console.time('findReturnTaskNodes总耗时')
// 使Set
const uniqueNodes = new Set<SimpleFlowNode>()
const currentNodeId = currentNode.value.id
const processedNodes = new Set<string>() //
//
console.time('父节点查找耗时')
emits('find:parentNode', matchNodeList, NodeType.USER_TASK_NODE)
console.timeEnd('父节点查找耗时')
// Set
//
matchNodeList.forEach(node => {
if (node.id !== currentNodeId) {
if (!processedNodes.has(node.id) && node.id !== currentNodeId) {
uniqueNodes.add(node)
processedNodes.add(node.id)
}
})
// Set
findChildUserTaskNodes(currentNode.value, uniqueNodes, currentNodeId)
//
findChildUserTaskNodes(currentNode.value, uniqueNodes, currentNodeId, processedNodes)
// Set
//
matchNodeList.length = 0
matchNodeList.push(...uniqueNodes)
matchNodeList.push(...Array.from(uniqueNodes))
console.log('[findReturnTaskNodes] 最终找到的节点数:', matchNodeList.length)
console.timeEnd('findReturnTaskNodes总耗时')
}
//
//
const findChildUserTaskNodes = (
node: SimpleFlowNode,
uniqueNodes: Set<SimpleFlowNode>,
currentNodeId: string
currentNodeId: string,
processedNodes: Set<string>
) => {
if (!node) return
if (!node || processedNodes.has(node.id)) return
processedNodes.add(node.id)
//
if (node.childNode) {
if (node.childNode.type === NodeType.USER_TASK_NODE && node.childNode.id !== currentNodeId) {
if (node.childNode.type === NodeType.USER_TASK_NODE &&
node.childNode.id !== currentNodeId &&
!processedNodes.has(node.childNode.id)) {
uniqueNodes.add(node.childNode)
processedNodes.add(node.childNode.id)
}
findChildUserTaskNodes(node.childNode, uniqueNodes, currentNodeId)
findChildUserTaskNodes(node.childNode, uniqueNodes, currentNodeId, processedNodes)
}
//
if (node.type === NodeType.CONDITION_BRANCH_NODE && node.conditionNodes) {
for (const conditionNode of node.conditionNodes) {
if (conditionNode.childNode) {
if (conditionNode.childNode.type === NodeType.USER_TASK_NODE &&
conditionNode.childNode.id !== currentNodeId) {
uniqueNodes.add(conditionNode.childNode)
}
findChildUserTaskNodes(conditionNode.childNode, uniqueNodes, currentNodeId)
findChildUserTaskNodes(conditionNode.childNode, uniqueNodes, currentNodeId, processedNodes)
}
}
}