|
@@ -1,14 +1,18 @@
|
|
|
import { EasyProcess } from './process.type'
|
|
import { EasyProcess } from './process.type'
|
|
|
|
|
+import { ref } from 'vue'
|
|
|
|
|
|
|
|
export class ProcessHelper {
|
|
export class ProcessHelper {
|
|
|
- processData: EasyProcess.NodeConfig
|
|
|
|
|
|
|
+ processData: ReturnType<typeof ref<EasyProcess.NodeConfig>>
|
|
|
|
|
|
|
|
constructor(processData: EasyProcess.NodeConfig) {
|
|
constructor(processData: EasyProcess.NodeConfig) {
|
|
|
- this.processData = processData
|
|
|
|
|
|
|
+ this.processData = ref(processData)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public setProcessData(processData: EasyProcess.NodeConfig) {
|
|
|
|
|
+ this.processData.value = processData
|
|
|
|
|
+ }
|
|
|
public getProcessData(): EasyProcess.NodeConfig {
|
|
public getProcessData(): EasyProcess.NodeConfig {
|
|
|
- return this.processData
|
|
|
|
|
|
|
+ return this.processData.value!
|
|
|
}
|
|
}
|
|
|
/**
|
|
/**
|
|
|
* 添加子节点
|
|
* 添加子节点
|
|
@@ -16,7 +20,7 @@ export class ProcessHelper {
|
|
|
* @param node 要添加的节点
|
|
* @param node 要添加的节点
|
|
|
*/
|
|
*/
|
|
|
public addNode(nodeId: string, node: EasyProcess.NodeConfig): boolean {
|
|
public addNode(nodeId: string, node: EasyProcess.NodeConfig): boolean {
|
|
|
- const target = this.findNode(nodeId, this.processData)
|
|
|
|
|
|
|
+ const target = this.findNode(nodeId, this.getProcessData())
|
|
|
if (!target) return false
|
|
if (!target) return false
|
|
|
|
|
|
|
|
// 根据类型处理不同结构
|
|
// 根据类型处理不同结构
|
|
@@ -38,9 +42,9 @@ export class ProcessHelper {
|
|
|
* 删除节点(递归查找)
|
|
* 删除节点(递归查找)
|
|
|
* @param nodeId 要删除的节点ID
|
|
* @param nodeId 要删除的节点ID
|
|
|
*/
|
|
*/
|
|
|
- public deleteNode(nodeId: string, current: EasyProcess.NodeConfig = this.processData): boolean {
|
|
|
|
|
|
|
+ public deleteNode(nodeId: string, current: EasyProcess.NodeConfig = this.getProcessData()): boolean {
|
|
|
// 禁止删除根节点
|
|
// 禁止删除根节点
|
|
|
- if (this.processData.nodeId === nodeId) return false
|
|
|
|
|
|
|
+ if (this.processData.value?.nodeId === nodeId) return false
|
|
|
// 删除子节点
|
|
// 删除子节点
|
|
|
if (current.childNode?.nodeId === nodeId) {
|
|
if (current.childNode?.nodeId === nodeId) {
|
|
|
current.childNode = current.childNode?.childNode ?? undefined
|
|
current.childNode = current.childNode?.childNode ?? undefined
|
|
@@ -55,7 +59,7 @@ export class ProcessHelper {
|
|
|
if (router.conditionNodes.length < before) {
|
|
if (router.conditionNodes.length < before) {
|
|
|
if (router.conditionNodes.length > 1) return true
|
|
if (router.conditionNodes.length > 1) return true
|
|
|
// 如果只剩一个条件节点,将路由节点删除
|
|
// 如果只剩一个条件节点,将路由节点删除
|
|
|
- return this.deleteNode(router.nodeId!, this.processData)
|
|
|
|
|
|
|
+ return this.deleteNode(router.nodeId!, this.getProcessData())
|
|
|
}
|
|
}
|
|
|
for (const c of router.conditionNodes) {
|
|
for (const c of router.conditionNodes) {
|
|
|
if (this.deleteNode(nodeId, c)) return true
|
|
if (this.deleteNode(nodeId, c)) return true
|
|
@@ -74,7 +78,7 @@ export class ProcessHelper {
|
|
|
* @param nodeData 更新的字段
|
|
* @param nodeData 更新的字段
|
|
|
*/
|
|
*/
|
|
|
public updateNode(nodeId: string, nodeData: Record<string, unknown>) {
|
|
public updateNode(nodeId: string, nodeData: Record<string, unknown>) {
|
|
|
- const target = this.findNode(nodeId, this.processData)
|
|
|
|
|
|
|
+ const target = this.findNode(nodeId, this.getProcessData())
|
|
|
if (!target) return false
|
|
if (!target) return false
|
|
|
target.nodeData = { ...target.nodeData, ...nodeData }
|
|
target.nodeData = { ...target.nodeData, ...nodeData }
|
|
|
return true
|
|
return true
|
|
@@ -103,7 +107,7 @@ export class ProcessHelper {
|
|
|
/**
|
|
/**
|
|
|
* 打印流程结构(调试用)
|
|
* 打印流程结构(调试用)
|
|
|
*/
|
|
*/
|
|
|
- public printTree(node: EasyProcess.NodeConfig = this.processData, indent = 0): void {
|
|
|
|
|
|
|
+ public printTree(node: EasyProcess.NodeConfig = this.getProcessData(), indent = 0): void {
|
|
|
if (indent == 0) console.log('====== 流程结构 ======')
|
|
if (indent == 0) console.log('====== 流程结构 ======')
|
|
|
console.log(`${' '.repeat(indent)}- ${node.nodeType} (${node.nodeName} | ${node.nodeId})`)
|
|
console.log(`${' '.repeat(indent)}- ${node.nodeType} (${node.nodeName} | ${node.nodeId})`)
|
|
|
if (node.nodeType === 'router') {
|
|
if (node.nodeType === 'router') {
|