|
|
@@ -1,4 +1,4 @@
|
|
|
-import { EasyProcess } from './process.type'
|
|
|
+import { Process } from './process.type'
|
|
|
import { ref, reactive } from 'vue'
|
|
|
|
|
|
/**
|
|
|
@@ -7,16 +7,16 @@ import { ref, reactive } from 'vue'
|
|
|
* ==========================================
|
|
|
*/
|
|
|
export class ProcessHelper {
|
|
|
- processData: ReturnType<typeof ref<EasyProcess.NodeConfig>>
|
|
|
+ processData: ReturnType<typeof ref<Process.NodeConfig>>
|
|
|
|
|
|
- constructor(processData: EasyProcess.NodeConfig) {
|
|
|
+ constructor(processData: Process.NodeConfig) {
|
|
|
this.processData = ref(processData)
|
|
|
}
|
|
|
|
|
|
- public setProcessData(processData: EasyProcess.NodeConfig) {
|
|
|
+ public setProcessData(processData: Process.NodeConfig) {
|
|
|
this.processData.value = processData
|
|
|
}
|
|
|
- public getProcessData(): EasyProcess.NodeConfig {
|
|
|
+ public getProcessData(): Process.NodeConfig {
|
|
|
return this.processData.value!
|
|
|
}
|
|
|
/**
|
|
|
@@ -24,16 +24,16 @@ export class ProcessHelper {
|
|
|
* @param nodeId 父节点ID
|
|
|
* @param node 要添加的节点
|
|
|
*/
|
|
|
- public addNode(nodeId: string, node: EasyProcess.NodeConfig): boolean {
|
|
|
+ public addNode(nodeId: string, node: Process.NodeConfig): boolean {
|
|
|
const target = this.findNode(nodeId, this.getProcessData())
|
|
|
if (!target) return false
|
|
|
|
|
|
// 根据类型处理不同结构
|
|
|
if (target.nodeType === 'router' && node.nodeType === 'condition') {
|
|
|
// 路由节点添加条件分支
|
|
|
- const router = target as EasyProcess.RouterNode
|
|
|
+ const router = target as Process.RouterNode
|
|
|
if (!router.conditionNodes) router.conditionNodes = []
|
|
|
- router.conditionNodes.push(node as EasyProcess.ConditionNode)
|
|
|
+ router.conditionNodes.push(node as Process.ConditionNode)
|
|
|
} else {
|
|
|
// 普通节点、条件节点添加 childNode
|
|
|
const childNode = target.childNode
|
|
|
@@ -47,7 +47,7 @@ export class ProcessHelper {
|
|
|
* 删除节点(递归查找)
|
|
|
* @param nodeId 要删除的节点ID
|
|
|
*/
|
|
|
- public deleteNode(nodeId: string, current: EasyProcess.NodeConfig = this.getProcessData()): boolean {
|
|
|
+ public deleteNode(nodeId: string, current: Process.NodeConfig = this.getProcessData()): boolean {
|
|
|
// 禁止删除根节点
|
|
|
if (this.processData.value?.nodeId === nodeId) return false
|
|
|
// 删除子节点
|
|
|
@@ -57,7 +57,7 @@ export class ProcessHelper {
|
|
|
}
|
|
|
// 删除条件节点(router专用)
|
|
|
if (current.nodeType === 'router') {
|
|
|
- const router = current as EasyProcess.RouterNode
|
|
|
+ const router = current as Process.RouterNode
|
|
|
const before = router.conditionNodes?.length ?? 0
|
|
|
if (router.conditionNodes) {
|
|
|
router.conditionNodes = router.conditionNodes.filter((c) => c.nodeId !== nodeId)
|
|
|
@@ -92,11 +92,11 @@ export class ProcessHelper {
|
|
|
/**
|
|
|
* 查找节点(深度优先)
|
|
|
*/
|
|
|
- private findNode(nodeId: string, current: EasyProcess.NodeConfig): EasyProcess.NodeConfig | null {
|
|
|
+ private findNode(nodeId: string, current: Process.NodeConfig): Process.NodeConfig | null {
|
|
|
if (current.nodeId === nodeId) return current
|
|
|
// router 条件节点
|
|
|
if (current.nodeType === 'router') {
|
|
|
- const router = current as EasyProcess.RouterNode
|
|
|
+ const router = current as Process.RouterNode
|
|
|
for (const c of router.conditionNodes || []) {
|
|
|
const found = this.findNode(nodeId, c)
|
|
|
if (found) return found
|
|
|
@@ -112,11 +112,11 @@ export class ProcessHelper {
|
|
|
/**
|
|
|
* 打印流程结构(调试用)
|
|
|
*/
|
|
|
- public printTree(node: EasyProcess.NodeConfig = this.getProcessData(), indent = 0): void {
|
|
|
+ public printTree(node: Process.NodeConfig = this.getProcessData(), indent = 0): void {
|
|
|
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
|
|
|
+ const router = node as Process.RouterNode
|
|
|
router.conditionNodes?.forEach((cond) => this.printTree(cond, indent + 2))
|
|
|
}
|
|
|
if (node.childNode) this.printTree(node.childNode, indent + 2)
|