Pre Merge pull request !724 from Lemon/feature/bpm-节点增强-并行

pull/724/MERGE
Lemon 2025-03-22 23:54:47 +00:00 committed by Gitee
commit c7392b2e2e
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 115 additions and 1 deletions

View File

@ -91,6 +91,7 @@ import {
DEFAULT_CONDITION_GROUP_VALUE
} from './consts'
import { generateUUID } from '@/utils'
import { isNodeInParallelBranch } from './utils'
defineOptions({
name: 'NodeHandler'
@ -113,7 +114,24 @@ const emits = defineEmits(['update:childNode'])
const readonly = inject<Boolean>('readonly') //
const addNode = (type: number) => {
//
const rootNode = inject<Ref<SimpleFlowNode>>('rootNode')
const addNode = async (type: number) => {
//
if (type === NodeType.CONDITION_BRANCH_NODE) {
if (!rootNode?.value) {
console.warn('No root node found')
return
}
//
if (isNodeInParallelBranch(props.currentNode, rootNode.value)) {
message.error('并行网关中不能执行条件分支,请转换为包容网关')
return
}
}
//
if (
type === NodeType.PARALLEL_BRANCH_NODE &&

View File

@ -86,6 +86,9 @@ const processNodeTree = useWatchNode(props)
provide('readonly', props.readonly)
//
provide('rootNode', processNodeTree)
// TODO
/** 拖拽、放大缩小等操作 */
let scaleValue = ref(100)

View File

@ -1,4 +1,5 @@
import { TimeUnitType, ApproveType, APPROVE_TYPE } from './consts'
import { SimpleFlowNode, NodeType } from './consts'
// 获取条件节点默认的名称
export const getDefaultConditionNodeName = (index: number, defaultFlow: boolean | undefined): string => {
@ -39,3 +40,95 @@ export const getApproveTypeText = (approveType: ApproveType): string => {
})
return approveTypeText
}
/**
*
* @param currentNode
* @param rootNode
* @returns boolean
*/
export function isNodeInParallelBranch(
currentNode: SimpleFlowNode,
rootNode: SimpleFlowNode
): boolean {
const path = findNodePath(currentNode, rootNode)
// 检查当前节点是否在并行分支的条件节点内
for (let i = 0; i < path.length; i++) {
const node = path[i]
if (node.type === NodeType.PARALLEL_BRANCH_NODE) {
// 如果找到并行分支节点,检查当前节点是否在其条件节点内
if (node.conditionNodes?.some(conditionNode => {
// 检查当前节点是否在这个条件分支的子树中
const subPath = findNodePath(currentNode, conditionNode)
if (subPath.length > 0) {
// 如果在条件分支内,检查是否在包容节点内
// 从当前节点向上查找最近的包容节点
for (const pathNode of subPath) {
if (pathNode.type === NodeType.INCLUSIVE_BRANCH_NODE) {
// 如果在包容节点内,允许创建条件分支
return false
}
}
return true
}
return false
})) {
return true
}
}
}
// 不在任何并行分支的条件节点内
return false
}
/**
*
* @param targetNode
* @param currentNode
* @param path
* @returns SimpleFlowNode[]
*/
export function findNodePath(
targetNode: SimpleFlowNode,
currentNode: SimpleFlowNode,
path: SimpleFlowNode[] = []
): SimpleFlowNode[] {
// 如果找到目标节点,返回路径
if (currentNode === targetNode) {
return [...path, currentNode]
}
// 检查条件分支节点
if (currentNode.conditionNodes) {
for (const conditionNode of currentNode.conditionNodes) {
// 在当前分支中搜索
const newPath = [...path, currentNode]
// 检查条件节点本身
if (conditionNode === targetNode) {
return [...newPath, conditionNode]
}
// 检查条件节点的子节点
if (conditionNode.childNode) {
const result = findNodePath(targetNode, conditionNode.childNode, newPath)
if (result.length > 0) {
return result
}
}
}
}
// 检查子节点
if (currentNode.childNode) {
const newPath = [...path, currentNode]
const result = findNodePath(targetNode, currentNode.childNode, newPath)
if (result.length > 0) {
return result
}
}
return []
}