|
|
@@ -6,6 +6,10 @@ export class ProcessHelper {
|
|
|
constructor(processData: EasyProcess.NodeConfig) {
|
|
|
this.processData = processData
|
|
|
}
|
|
|
+
|
|
|
+ public getProcessData(): EasyProcess.NodeConfig {
|
|
|
+ return this.processData
|
|
|
+ }
|
|
|
/**
|
|
|
* 添加子节点
|
|
|
* @param nodeId 父节点ID
|
|
|
@@ -16,13 +20,15 @@ export class ProcessHelper {
|
|
|
if (!target) return false
|
|
|
|
|
|
// 根据类型处理不同结构
|
|
|
- if (target.nodeType === 'router') {
|
|
|
+ if (target.nodeType === 'router' && node.nodeType === 'condition') {
|
|
|
// 路由节点添加条件分支
|
|
|
const router = target as EasyProcess.RouterNode
|
|
|
if (!router.conditionNodes) router.conditionNodes = []
|
|
|
router.conditionNodes.push(node as EasyProcess.ConditionNode)
|
|
|
} else {
|
|
|
// 普通节点、条件节点添加 childNode
|
|
|
+ const childNode = target.childNode
|
|
|
+ if (childNode) node.childNode = childNode
|
|
|
target.childNode = node
|
|
|
}
|
|
|
return true
|
|
|
@@ -33,9 +39,11 @@ export class ProcessHelper {
|
|
|
* @param nodeId 要删除的节点ID
|
|
|
*/
|
|
|
public deleteNode(nodeId: string, current: EasyProcess.NodeConfig = this.processData): boolean {
|
|
|
+ // 禁止删除根节点
|
|
|
+ if (this.processData.nodeId === nodeId) return false
|
|
|
// 删除子节点
|
|
|
if (current.childNode?.nodeId === nodeId) {
|
|
|
- current.childNode = undefined
|
|
|
+ current.childNode = current.childNode?.childNode ?? undefined
|
|
|
return true
|
|
|
}
|
|
|
// 删除条件节点(router专用)
|
|
|
@@ -44,7 +52,11 @@ export class ProcessHelper {
|
|
|
const before = router.conditionNodes?.length ?? 0
|
|
|
if (router.conditionNodes) {
|
|
|
router.conditionNodes = router.conditionNodes.filter((c) => c.nodeId !== nodeId)
|
|
|
- if (router.conditionNodes.length < before) return true
|
|
|
+ if (router.conditionNodes.length < before) {
|
|
|
+ if (router.conditionNodes.length > 1) return true
|
|
|
+ // 如果只剩一个条件节点,将路由节点删除
|
|
|
+ return this.deleteNode(router.nodeId!, this.processData)
|
|
|
+ }
|
|
|
for (const c of router.conditionNodes) {
|
|
|
if (this.deleteNode(nodeId, c)) return true
|
|
|
}
|
|
|
@@ -92,7 +104,8 @@ export class ProcessHelper {
|
|
|
* 打印流程结构(调试用)
|
|
|
*/
|
|
|
public printTree(node: EasyProcess.NodeConfig = this.processData, indent = 0): void {
|
|
|
- console.log(`${' '.repeat(indent)}- ${node.nodeType} (${node.nodeName})`)
|
|
|
+ if (indent == 0) console.log('====== 流程结构 ======')
|
|
|
+ console.log(`${' '.repeat(indent)}- ${node.nodeType} (${node.nodeName} | ${node.nodeId})`)
|
|
|
if (node.nodeType === 'router') {
|
|
|
const router = node as EasyProcess.RouterNode
|
|
|
router.conditionNodes?.forEach((cond) => this.printTree(cond, indent + 2))
|