wujingjing
2024-12-16 890adec7fddfe9d5f5da4511343ac6e8341d46b3
src/components/vue-flow/ui/nodes/StartNode.vue
@@ -1,126 +1,76 @@
<template>
   <div
      class="w-max-[520px] border-2 rounded-lg border-solid border-gray-100 bg-white p-3 shadow-md relative hover:border-blue-500 group"
   <NodeBasicLayout
      v-model:title="data.title"
      :type="NodeType.Start"
      :description="VueFlowHelper.getConfigValue(data, 'description', '工作流运行的起始节点。')"
   >
      <div
         class="group-hover:visible invisible flex absolute divide-y-[1.5px] divide-solid divide-gray-100 rounded-lg right-0 -top-0.5 translate-y-[-100%]"
         style="box-shadow: 0 0 15px #dbdee6"
      >
         <el-tooltip effect="dark" content="复制" placement="top">
            <div
               class="flex content-center items-center border-x-0 p-1 hover:bg-gray-200 active:bg-gray-300 cursor-pointer"
               @click="handleClickDuplicateBtn"
            >
               <span class="ywifont !text-[20px] mb-1 p-1.5 ywicon-copy"></span>
            </div>
         </el-tooltip>
         <el-tooltip effect="dark" content="删除" placement="top">
            <div
               @click="clickDeleteBtn"
               class="flex content-center items-center border-x-0 p-1 hover:bg-gray-200 active:bg-gray-300 hover:text-red-400 cursor-pointer"
            >
               <span class="ywifont !text-[20px] mb-1 p-1.5 ywicon-shanchu"></span>
            </div>
         </el-tooltip>
      </div>
      <div class="flex flex-col gap-y-2">
         <div class="flex justify-between flex-0">
            <div class="flex items-center gap-x-2">
               <img src="/@/components/vue-flow/ui/assets/images/icon_Start.png" class="h-4 w-4" alt="Start icon" />
               <div class="flex flex-col gap-y-1">
                  <p v-if="!titleIsEdit" class="text-xl font-bold text-gray-500" @click="titleIsEdit = true">{{ data.title }}</p>
                  <el-input v-elInputFocus v-else v-model="data.title" @blur="() => (titleIsEdit = false)"></el-input>
               </div>
            </div>
         </div>
      <FieldLayout :title="VueFlowHelper.getConfigValue(varListConfig, 'name', '流程参数')">
         <el-table class="flex-auto" :data="varList" border>
            <el-table-column prop="name" width="90" label="参数名" fixed>
               <template #default="scope">
                  <el-input v-model="scope.row.name"></el-input>
               </template>
            </el-table-column>
            <el-table-column prop="type" width="120" label="类型">
               <template #default="scope">
                  <el-select v-model="scope.row.type">
                     <el-option
                        v-for="item in Object.keys(parameterTypeMap)"
                        :key="item"
                        :value="item"
                        :label="parameterTypeMap[item]"
                     ></el-option>
                  </el-select>
               </template>
            </el-table-column>
            <el-table-column prop="description" width="180" label="描述">
               <template #default="scope">
                  <el-input type="textarea" :rows="1" v-model="scope.row.description"></el-input>
               </template>
            </el-table-column>
            <el-table-column prop="isRequired" width="56" label="必填">
               <template #default="scope">
                  <el-checkbox v-model="scope.row.isRequired"></el-checkbox>
               </template>
            </el-table-column>
         <div class="flex-auto gap-y-2 flex-col flex nodrag">
            <div class="text-lg font-bold">参数</div>
            <el-table size="small" class="flex-auto" :data="varList" border>
               <el-table-column prop="name" width="90" label="参数名" fixed>
                  <template #default="scope">
                     <el-input v-model="scope.row.name"></el-input>
                  </template>
               </el-table-column>
               <el-table-column prop="type" width="120" label="类型">
                  <template #default="scope">
                     <el-select v-model="scope.row.type">
                        <el-option
                           v-for="item in Object.keys(parameterTypeMap)"
                           :key="item"
                           :value="item"
                           :label="parameterTypeMap[item]"
                        ></el-option>
                     </el-select>
                  </template>
               </el-table-column>
               <el-table-column prop="description" width="180" label="描述">
                  <template #default="scope">
                     <el-input type="textarea" :rows="1" v-model="scope.row.description"></el-input>
                  </template>
               </el-table-column>
               <el-table-column prop="isRequired" width="56" label="必填">
                  <template #default="scope">
                     <el-checkbox v-model="scope.row.isRequired"></el-checkbox>
                  </template>
               </el-table-column>
               <el-table-column label="操作" width="55" fixed="right">
                  <template #default="scope">
                     <el-tooltip effect="dark" content="删除" placement="top">
                        <i
                           class="ywifont ywicon-shanchu !text-[17px] text-red-400 cursor-pointer"
                           @click="handleClickDeleteBtn(scope.$index)"
                        ></i>
                     </el-tooltip>
                  </template>
               </el-table-column>
            </el-table>
            <el-button class="w-fit" type="primary" @click="handleClickAddBtn">添加参数</el-button>
         </div>
      </div>
            <el-table-column label="操作" width="55" fixed="right">
               <template #default="scope">
                  <el-tooltip effect="dark" content="删除" placement="top">
                     <i
                        class="ywifont ywicon-shanchu !text-[17px] text-red-400 cursor-pointer"
                        @click="handleClickDeleteBtn(scope.$index)"
                     ></i>
                  </el-tooltip>
               </template>
            </el-table-column>
         </el-table>
         <el-button class="w-fit" type="primary" @click="handleClickAddBtn">添加参数</el-button>
      </FieldLayout>
      <Handle :id="handleId" type="source" :position="Position.Right" />
   </div>
   <!-- <div>
      <span>起始</span>
      <Handle type="source" :position="Position.Right" />
   </div> -->
   </NodeBasicLayout>
</template>
<script lang="ts" setup>
import { Handle, Position, useNode, useVueFlow } from '@vue-flow/core';
import { ref, watchEffect } from 'vue';
import { ref } from 'vue';
import type { NodeProps } from '@vue-flow/core';
import { computed } from 'vue';
import { VueFlowConstant } from '../../VueFlowConstant';
import { VueFlowHelper } from '../../VueFlowHelper';
import { parameterTypeMap } from '../../vueFlowEnum';
import { NodeType, parameterTypeMap } from '../../vueFlowEnum';
import { LLMNodeData, LLMNodeEvents } from './index';
import { deepClone } from '/@/utils/other';
import NodeBasicLayout from './components/NodeBasicLayout.vue';
import FieldLayout from './components/FieldLayout.vue';
defineProps<NodeProps<LLMNodeData, LLMNodeEvents>>();
const node = useNode();
const handleId = ref(VueFlowHelper.getHandleId(node.node, 'source'));
const data = ref(node.node.data);
const getVarList = () =>{
   const varList = data.value[VueFlowConstant.GROUP_PARAMS_KEY][0][VueFlowConstant.PARAMS_KEY].find(
      (item) => item.key === 'condition'
   ).value;
   return varList;
}
const varList = ref(VueFlowHelper.getFieldValue(data.value,'var_list'));
const titleIsEdit = ref(false);
const varList = ref(VueFlowHelper.getFieldValue(data.value, 'var_list'));
function handleClickAddBtn() {
   varList.value.push({
      name: '',
      description: '',
@@ -128,29 +78,14 @@
      isRequired: true,
   });
}
const varListConfig = ref(VueFlowHelper.getGroupParam(data.value, 0));
const varListParam = ref(VueFlowHelper.getParams(varListConfig.value, 'var_list'));
VueFlowHelper.getConfigValue(varListParam.value, 'label', '');
function handleClickDeleteBtn(index: number) {
   varList.value.splice(index, 1);
}
const { removeNodes, nodes, addNodes } = useVueFlow();
function handleClickDuplicateBtn() {
   const { type, position, data } = node.node;
   const newNode = {
      id: VueFlowHelper.genGeometryId(),
      type,
      position: {
         x: position.x + 100,
         y: position.y + 100,
      },
      data: deepClone(data),
   };
   addNodes(newNode);
}
const clickDeleteBtn = () => {
   removeNodes(node.id);
};
</script>