Kaynağa Gözat

开始节点

CzRger 3 gün önce
ebeveyn
işleme
7de643e325

+ 54 - 1
src/views/workflow/handle.ts

@@ -11,11 +11,41 @@ const systemVars = [
     source: VarsSource.Root,
   },
   {
+    label: '对话数量',
+    key: 'sys.dialogue_count',
+    type: 'Number',
+    source: VarsSource.Root,
+  },
+  {
+    label: '会话ID',
+    key: 'sys.conversation_id',
+    type: 'String',
+    source: VarsSource.Root,
+  },
+  {
     label: '用户ID',
     key: 'sys.user_id',
     type: 'String',
     source: VarsSource.Root,
   },
+  {
+    label: '应用ID',
+    key: 'sys.app_id',
+    type: 'String',
+    source: VarsSource.Root,
+  },
+  {
+    label: '工作流ID',
+    key: 'sys.workflow_id',
+    type: 'String',
+    source: VarsSource.Root,
+  },
+  {
+    label: '工作流运行ID',
+    key: 'sys.workflow_run_id',
+    type: 'String',
+    source: VarsSource.Root,
+  },
 ]
 export const handleNode = (no) => {
   const id = v4()
@@ -125,7 +155,6 @@ export const handleNode = (no) => {
   }
   return node
 }
-
 export const handleEdge = (ed) => {
   const id = v4()
   if (!ed.id) {
@@ -173,3 +202,27 @@ export const handleEdge = (ed) => {
   }
   return edge
 }
+export const handleNodeSubmit = (no) => {
+  console.log(no)
+  switch (no.type) {
+    case NodeType.Start:
+      {
+        no.variables = no.outVars.map((v) => {
+          const obj = {
+            variable: v.key,
+            label: v.label,
+            type: v.type.toLowerCase(),
+            required: v.required,
+          }
+          if (v.type === 'String') {
+            obj.max_length = Number(v.length)
+          } else if (v.type === 'Select') {
+            obj.options = v.options
+          }
+          return obj
+        })
+      }
+      break
+  }
+  return no
+}

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

@@ -49,6 +49,7 @@ import {
 import { ElLoading, ElMessage } from 'element-plus'
 import { debounce } from 'lodash'
 import { YMDHms } from '@/utils/czr-util'
+import { handleNodeSubmit } from '@/views/workflow/handle'
 
 const TeleportContainer = getTeleport()
 const WorkflowStore = useWorkflowStore()
@@ -95,7 +96,7 @@ const onSave = () => {
         id: cell.id,
         type: cell.data.workflowData.type,
         position: cell.position,
-        data: cell.data.workflowData,
+        data: handleNodeSubmit(cell.data.workflowData),
       }
       delete node.data.edgeSource
       delete node.data.inVars

+ 44 - 6
src/views/workflow/instance/component/vars/vars-detail.vue

@@ -34,9 +34,7 @@
           label="变量名称"
           v-model:param="state.form.key"
         />
-        <template
-          v-if="state.form.type === 'String' || state.form.type === 'Textarea'"
-        >
+        <template v-if="state.form.type === 'String'">
           <CzrFormColumn
             :span="24"
             required
@@ -44,6 +42,38 @@
             v-model:param="state.form.length"
           />
         </template>
+        <template v-if="state.form.type === 'Select'">
+          <div class="mb-2 w-full">
+            <el-button @click="state.options.push({ value: '' })"
+              >添加下拉选项</el-button
+            >
+          </div>
+          <template v-for="(item, index) in state.options">
+            <div class="mb-2 flex w-full items-center">
+              <CzrFormColumn
+                class="__czr-table-form-column"
+                :span="22"
+                required
+                :label="`选项${index + 1}`"
+                v-model:param="item.value"
+                layout="x"
+              />
+              <SvgIcon
+                v-if="state.options.length > 1"
+                name="czr_del"
+                class="__hover ml-2"
+                @click="state.options.splice(index, 1)"
+              />
+            </div>
+          </template>
+        </template>
+        <CzrFormColumn
+          :span="24"
+          required
+          label="是否必填"
+          v-model:param="state.form.required"
+          link="switch"
+        />
       </CzrForm>
     </div>
   </CzrDialog>
@@ -60,6 +90,8 @@ import {
 } from 'vue'
 import { ElMessage, ElMessageBox } from 'element-plus'
 import { VarsSource } from '@/views/workflow/types'
+import CzrDialog from '@/components/czr-ui/CzrDialog.vue'
+import CzrForm from '@/components/czr-ui/CzrForm.vue'
 
 const emit = defineEmits(['update:show', 'refresh'])
 const { proxy } = getCurrentInstance()
@@ -73,12 +105,12 @@ const state: any = reactive({
   form: {
     type: 'String',
   },
+  options: [{ value: '' }],
 })
 const optionsType = [
   { type: 'String', label: '文本' },
-  // {type: 'Textarea', label: '段落'},
   { type: 'Number', label: '数字' },
-  // {type: 'Select', label: '下拉选项'},
+  { type: 'Select', label: '下拉选项' },
 ]
 const titleCpt = computed(() => {
   let t = '变量'
@@ -101,6 +133,9 @@ watch(
         type: 'String',
         source: VarsSource.Param,
       }
+      if (state.form.type === 'Select') {
+        state.options = state.form.options.map((v) => ({ value: v }))
+      }
       nextTick(() => {
         ref_form.value.reset()
       })
@@ -116,9 +151,12 @@ const onSubmit = () => {
         label: state.form.label,
         key: state.form.key,
         type: state.form.type,
+        required: state.form.required,
       }
-      if (state.form.type === 'String' || state.form.type === 'Textarea') {
+      if (state.form.type === 'String') {
         res.length = state.form.length
+      } else if (state.form.type === 'Select') {
+        res.options = state.options.map((v) => v.value)
       }
       emit('refresh', res)
     })

+ 1 - 0
src/views/workflow/instance/component/vars/vars-item.vue

@@ -19,6 +19,7 @@
       <span v-if="item.label" class="opacity-65"> · {{ item.label }}</span>
     </div>
     <span class="ml-auto opacity-65">{{ item.type }}</span>
+    <span v-if="item.required" class="text-red-500">*</span>
     <template v-if="state.hover">
       <SvgIcon
         v-if="edit"

+ 1 - 0
src/views/workflow/instance/component/vars/vars-out.vue

@@ -4,6 +4,7 @@
       <div class="out-item">
         <div>
           {{ item.key }} <span class="ml-2 opacity-65">{{ item.type }}</span>
+          <span v-if="item.required" class="text-red-500">*</span>
         </div>
         <div>
           <span class="opacity-65">{{ item.label }}</span>

+ 1 - 0
src/views/workflow/instance/component/vars/vars-value.vue

@@ -20,6 +20,7 @@
       <span class="opacity-65">{{ vars.label }}</span>
     </div>
     <span class="opacity-65">{{ vars.type }}</span>
+    <span v-if="vars.required" class="text-red-500">*</span>
   </div>
   <div v-else class="opacity-65">{x}请选择变量</div>
 </template>