CzRger 2 周之前
父节点
当前提交
7d71c9f179

+ 4 - 0
src/stores/modules/workflow.ts

@@ -16,6 +16,7 @@ export const useWorkflowStore = defineStore('workflow', {
     },
     nodeSize: {},
     autoSaveFlag: false,
+    nodeRelationChangeFlag: false,
   }),
   getters: {},
   actions: {
@@ -120,5 +121,8 @@ export const useWorkflowStore = defineStore('workflow', {
       console.log('自动保存触发')
       this.autoSaveFlag = !this.autoSaveFlag
     },
+    nodeRelationChange() {
+      this.nodeRelationChangeFlag = !this.nodeRelationChangeFlag
+    },
   },
 })

+ 13 - 12
src/views/workflow/chart/context-menu-tool.tsx

@@ -27,19 +27,20 @@ class ContextMenuTool extends ToolsView.ToolItem {
 
     if (visible && pos) {
       const { data, delFlag }: any = this.options
-      if (data.data.type !== NodeType.Start) {
-        app = createApp(contextMenuTool, {
-          data,
-          delFlag,
-          onClose: this.onMouseDown,
-        })
-        // 减去本身元素的宽高
-        if (dom) {
-          dom.style = `left: ${pos.x}px;top: ${pos.y}px;position: absolute;z-index: 100;`
-        }
-        app.mount(`#${ID}`)
-        document.addEventListener('mousedown', this.onMouseDown)
+      if (data.data?.type === NodeType.Start) {
+        return
       }
+      app = createApp(contextMenuTool, {
+        data,
+        delFlag,
+        onClose: this.onMouseDown,
+      })
+      // 减去本身元素的宽高
+      if (dom) {
+        dom.style = `left: ${pos.x}px;top: ${pos.y}px;position: absolute;z-index: 100;`
+      }
+      app.mount(`#${ID}`)
+      document.addEventListener('mousedown', this.onMouseDown)
     }
   }
 

+ 11 - 0
src/views/workflow/chart/index.vue

@@ -607,6 +607,16 @@ const initWatch = () => {
       state.history.canRedo = state.graph.canRedo()
       state.history.canUndo = state.graph.canUndo()
       if (options.name) {
+        if (
+          [
+            GraphHistoryStep.NodeAdd,
+            GraphHistoryStep.NodeDel,
+            GraphHistoryStep.EdgeAdd,
+            GraphHistoryStep.EdgeDel,
+          ].includes(options.name)
+        ) {
+          WorkflowStore.nodeRelationChange()
+        }
         const arr = [options.name]
         state.history.steps.forEach((v, i) => {
           if (i >= state.history.current) {
@@ -685,6 +695,7 @@ const graphZoom = (z) => {
   }
 }
 const onHistoryDo = (step) => {
+  WorkflowStore.nodeRelationChange()
   if (step > 0) {
     for (let i = 1; i <= step; i++) {
       if (state.history.canRedo) {

+ 7 - 0
src/views/workflow/handle.ts

@@ -379,3 +379,10 @@ export const handleNodeSubmit = (no) => {
   }
   return no
 }
+export const handleEnv = (arr) => {
+  return arr.map((v) => ({
+    ...v,
+    name: v.key,
+    value_type: v.type.toLowerCase(),
+  }))
+}

+ 2 - 2
src/views/workflow/index.vue

@@ -47,7 +47,7 @@ import {
 } from '@/api/modules/workflow/chart'
 import { ElLoading, ElMessage } from 'element-plus'
 import { debounce } from 'lodash'
-import { handleNodeSubmit } from '@/views/workflow/handle'
+import { handleEnv, handleNodeSubmit } from '@/views/workflow/handle'
 
 const DictionaryStore = useDictionaryStore()
 const AppStore = useAppStore()
@@ -78,7 +78,7 @@ const onSave = () => {
   const offset = WorkflowStore.graph.translate()
   const res: any = {
     conversationVariables: [],
-    environmentVariables: WorkflowStore.envVars.vars,
+    environmentVariables: handleEnv(WorkflowStore.envVars.vars),
     hash: state.uniqueHash,
     graph: {
       nodes: [],

+ 7 - 3
src/views/workflow/instance/component/params-textarea/version-2.vue

@@ -178,15 +178,17 @@ watch(
 )
 
 watch(
-  () => props.node,
+  () => [props.node, WorkflowStore.nodeRelationChangeFlag],
   (n) => {
-    if (n) {
-      const all = WorkflowStore.getInVars(n)
+    if (n[0]) {
+      const all = WorkflowStore.getInVars(n[0])
       const map = new Map()
       all.forEach((p) => {
         p.options.forEach((v) => {
           if (v.source === VarsSource.Root) {
             map.set(`${v.key}`, v)
+          } else if (v.source === VarsSource.Env) {
+            map.set(`env.${v.key}`, v)
           } else {
             map.set(`${v.nodeId}.${v.key}`, v)
           }
@@ -347,6 +349,8 @@ const initVarsDom = (vars) => {
     dom.setAttribute('contenteditable', 'false')
     if (vars.source === VarsSource.Root) {
       dom.setAttribute('sign', `{{#${vars.key}#}}`)
+    } else if (vars.source === VarsSource.Env) {
+      dom.setAttribute('sign', `{{#env.${vars.key}#}}`)
     } else {
       dom.setAttribute('sign', `{{#${vars.nodeId}.${vars.key}#}}`)
     }

+ 3 - 0
src/views/workflow/instance/component/vars/env-detail.vue

@@ -153,6 +153,9 @@ const onSubmit = () => {
         border-color: var(--czr-main-color);
         color: var(--czr-main-color);
       }
+      &.active {
+        background-color: #ffffff;
+      }
     }
   }
   .vars-detail-form {

+ 3 - 3
src/views/workflow/instance/component/vars/vars-popover.vue

@@ -66,10 +66,10 @@ const state: any = reactive({
   show: false,
 })
 watch(
-  () => props.node,
+  () => [props.node, WorkflowStore.nodeRelationChangeFlag],
   (n) => {
-    if (n) {
-      const all = WorkflowStore.getInVars(n)
+    if (n[0]) {
+      const all = WorkflowStore.getInVars(n[0])
       state.options = props.filter.type
         ? all
             .map((v) => {