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

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

View File

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