Przeglądaj źródła

feat: 流程设计

zhanghaijun 1 rok temu
rodzic
commit
8ec5fddc5c

+ 59 - 0
src/components/business/EasyProcess/common/validator.util.ts

@@ -0,0 +1,59 @@
+import { reactive } from 'vue'
+
+/** 验证结果 */
+export interface ValidationResult {
+  valid: boolean
+  message?: string
+}
+
+/** 验证函数类型(可携带上下文参数) */
+export type ValidatorFn<T> = (context: T) => ValidationResult
+
+/** Validator 类(支持泛型上下文) */
+export class Validator<T = void> {
+  private nodeRules: Map<string, ValidatorFn<T>> = new Map()
+  public results: Map<string, ValidationResult> = reactive(new Map())
+
+  /** 注册节点验证规则 */
+  register(nodeId: string, validatorFun: ValidatorFn<T>): void {
+    if (typeof validatorFun === 'function') {
+      this.nodeRules.set(nodeId, validatorFun)
+    }
+  }
+
+  /** 移除节点验证规则 */
+  remove(nodeId: string): void {
+    this.nodeRules.delete(nodeId)
+    this.results.delete(nodeId)
+  }
+
+  /** 执行验证,支持传递上下文 */
+  validate(context: T): { valid: boolean; messages: string[] } {
+    let valid = true
+    const messages: string[] = []
+
+    this.nodeRules.forEach((fun, key) => {
+      const result = fun(context)
+      if (!result.valid) {
+        valid = false
+        this.results.set(key, result)
+        if (result.message) messages.push(result.message)
+      } else {
+        this.results.delete(key)
+      }
+    })
+
+    return { valid, messages }
+  }
+
+  /** 获取指定节点的结果 */
+  getResult(nodeId: string): ValidationResult | undefined {
+    return this.results.get(nodeId)
+  }
+
+  /** 清空所有规则和结果 */
+  clear(): void {
+    this.nodeRules.clear()
+    this.results.clear()
+  }
+}

+ 3 - 3
src/components/business/EasyProcess/node/base/BaseNode.vue

@@ -99,12 +99,12 @@
     node: {
       // 传入的流程节点数据
       type: Object,
-      default: {}
+      default: () => {}
     },
     conditionNodes: {
       // 条件集合,当节点类型为condition时有效
       type: Array,
-      default: []
+      default: () => []
     },
     conditionIndex: {
       // 当前条件节点的顺序,当节点类型为condition时有效
@@ -128,7 +128,7 @@
 
   watch(
     () => props.node,
-    (val) => {
+    () => {
       config.value = nodeConfig[props.node.nodeType]
       validator.validate()
     }

+ 3 - 7
src/components/business/EasyProcess/node/notify/notifyNode.vue

@@ -4,8 +4,8 @@
 </template>
 
 <script setup name="NotifyNode">
-  import { getCurrentInstance, inject } from 'vue'
-  import { KEY_PROCESS_DATA, KEY_VALIDATOR } from '../../config/keys'
+  import { inject } from 'vue'
+  import { KEY_VALIDATOR } from '../../config/keys'
 
   const props = defineProps({
     tempNodeId: {
@@ -15,14 +15,10 @@
     node: {
       // 传入的流程配置数据
       type: Object,
-      default: {}
+      default: () => {}
     }
   })
 
-  const { proxy } = getCurrentInstance()
-
-  // 获取流程数据
-  const processData = inject(KEY_PROCESS_DATA)
   // 获取流程验证器实例
   const validator = inject(KEY_VALIDATOR)
 

+ 1 - 1
src/components/business/EasyProcess/node/start/startNode.vue

@@ -15,7 +15,7 @@
     node: {
       // 传入的流程配置数据
       type: Object,
-      default: {}
+      default: () => {}
     }
   })
   // 获取流程验证器实例