| | |
| | | <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.Condition" |
| | | :description="VueFlowHelper.getConfigValue(data, 'description', '根据条件表达式执行不同的分支。')" |
| | | :isViewMode="isViewMode" |
| | | > |
| | | <Handle :id="leftId" type="target" :position="Position.Left" /> |
| | | <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" |
| | | <FieldLayout |
| | | v-for="(item, index) in conditionGroupList" |
| | | :key="item.id" |
| | | class="relative group/conditionGroup" |
| | | :title="item.conditions ? '如果' : '否则'" |
| | | > |
| | | <el-tooltip effect="dark" content="复制" placement="top"> |
| | | <template #right v-if="item.conditions"> |
| | | <el-select v-model="item.operator" class="w-[130px]" :disabled="isViewMode"> |
| | | <el-option |
| | | v-for="item in Object.keys(conditionOperatorMap)" |
| | | :key="item" |
| | | :value="item" |
| | | :label="conditionOperatorMap[item]" |
| | | ></el-option> |
| | | </el-select> |
| | | |
| | | <span |
| | | v-if="!isViewMode" |
| | | class="ywifont ywicon-shanchu text-red-400 invisible group-hover/conditionGroup:visible cursor-pointer" |
| | | @click="delConditionBranch(index)" |
| | | ></span> |
| | | </template> |
| | | <div class="flex flex-col gap-y-2" v-if="item.conditions"> |
| | | <div |
| | | class="flex content-center items-center border-x-0 p-1 hover:bg-gray-200 active:bg-gray-300 cursor-pointer" |
| | | @click="handleClickDuplicateBtn" |
| | | v-for="(subItem, subIndex) in item.conditions" |
| | | :key="subIndex" |
| | | class="ml-5 flex-items-center gap-x-2 group/conditionItem pr-8" |
| | | > |
| | | <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 min-w-[400px]"> |
| | | <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> |
| | | <el-input :readonly="isViewMode" filterable class="w-[120px] flex-0" v-model="subItem.left_value" placeholder="输入变量"> |
| | | </el-input> |
| | | <el-select |
| | | :disabled="isViewMode" |
| | | filterable |
| | | v-model="subItem.comparison_operation" |
| | | class="flex-0 w-[120px]" |
| | | placeholder="选择条件" |
| | | > |
| | | <el-option |
| | | v-for="operation in Object.keys(compareOperationMap)" |
| | | :key="operation" |
| | | :value="operation" |
| | | :label="compareOperationMap[operation]" |
| | | ></el-option> |
| | | </el-select> |
| | | |
| | | <div class="flex-auto gap-y-2 flex-col flex nodrag"> |
| | | <div v-for="(item, index) in conditionGroupList" class="flex-column gap-3 relative group/conditionGroup"> |
| | | <div class="flex-items-center justify-between"> |
| | | <div class="text-lg font-bold">如果</div> |
| | | <div class="flex-items-center gap-3"> |
| | | <el-select v-model="item.operator" class="w-[130px]"> |
| | | <el-option |
| | | v-for="item in Object.keys(conditionOperatorMap)" |
| | | :key="item" |
| | | :value="item" |
| | | :label="conditionOperatorMap[item]" |
| | | ></el-option> |
| | | </el-select> |
| | | <!-- v-if="conditionGroupList.length > 1" --> |
| | | |
| | | <span |
| | | class="ywifont ywicon-shanchu text-red-400 invisible group-hover/conditionGroup:visible cursor-pointer" |
| | | @click="delConditionBranch(index)" |
| | | ></span> |
| | | </div> |
| | | </div> |
| | | |
| | | <div class="flex-column gap-y-2"> |
| | | <div v-for="(subItem, subIndex) in item.conditions" class="ml-5 flex-items-center gap-x-2 group/conditionItem"> |
| | | <el-input |
| | | filterable |
| | | class="w-[120px] flex-0" |
| | | v-model="subItem.left_value" |
| | | |
| | | placeholder="输入变量" |
| | | > |
| | | </el-input> |
| | | <el-select v-model="subItem.comparison_operation" class="flex-0 w-[120px]" placeholder="选择条件"> |
| | | <el-option |
| | | v-for="item in Object.keys(compareOperationMap)" |
| | | :key="item" |
| | | :value="item" |
| | | :label="compareOperationMap[item]" |
| | | ></el-option> |
| | | </el-select> |
| | | |
| | | <el-select v-model="subItem.right_value_type" class="flex-0 w-[90px]" placeholder="请选择"> |
| | | <!-- <el-select v-model="subItem.right_value_type" class="flex-0 w-[90px]" placeholder="请选择"> |
| | | <el-option v-for="item in Object.keys(varTypeMap)" :key="item" :value="item" :label="varTypeMap[item]"></el-option> |
| | | </el-select> |
| | | </el-select> --> |
| | | <template v-if="isShowRight(subItem)"> |
| | | <el-input |
| | | :readonly="isViewMode" |
| | | v-if="subItem.right_value_type === VarType.Input" |
| | | v-model="subItem.right_value" |
| | | class="w-[180px]" |
| | | placeholder="输入值" |
| | | > |
| | | </el-input> |
| | | |
| | | <el-input |
| | | v-if="subItem.right_value_type === VarType.Input" |
| | | v-model="subItem.right_value" |
| | | class="w-[120px]" |
| | | placeholder="输入值" |
| | | > |
| | | </el-input> |
| | | <el-tree-select |
| | | v-else |
| | | :disabled="isViewMode" |
| | | filterable |
| | | class="w-[120px] flex-0" |
| | | v-model="subItem.right_value" |
| | | :data="treeReferOptions" |
| | | node-key="id" |
| | | :clearable="true" |
| | | :accordion="false" |
| | | :expandNode="false" |
| | | :check-strictly="false" |
| | | placeholder="选择变量" |
| | | > |
| | | </el-tree-select> |
| | | </template> |
| | | |
| | | <el-tree-select |
| | | v-else |
| | | filterable |
| | | class="w-[120px] flex-0" |
| | | v-model="subItem.right_value" |
| | | :data="treeReferOptions" |
| | | node-key="id" |
| | | :clearable="true" |
| | | :accordion="false" |
| | | :expandNode="false" |
| | | :check-strictly="false" |
| | | placeholder="选择变量" |
| | | > |
| | | </el-tree-select> |
| | | |
| | | <span |
| | | class="ywifont ywicon-shanchu text-red-400 invisible group-hover/conditionItem:visible cursor-pointer" |
| | | @click="delConditionItem(item, subIndex)" |
| | | ></span> |
| | | </div> |
| | | <el-button class="w-fit mt-3" type="primary" @click="addConditionItem(item)">添加条件</el-button> |
| | | </div> |
| | | <Handle :id="item.id" type="source" :position="Position.Right" /> |
| | | <span |
| | | v-if="!isViewMode" |
| | | class="ywifont ywicon-shanchu text-red-400 invisible group-hover/conditionItem:visible cursor-pointer" |
| | | @click="delConditionItem(item, subIndex)" |
| | | ></span> |
| | | </div> |
| | | |
| | | <div class="flex-column gap-3 relative"> |
| | | <div class="flex-items-center justify-between"> |
| | | <div class="text-lg font-bold">否则</div> |
| | | <!-- <el-select class="w-[130px]"> |
| | | <el-option |
| | | v-for="item in Object.keys(conditionOperatorMap)" |
| | | :key="item" |
| | | :value="parseInt(item)" |
| | | :label="conditionOperatorMap[item]" |
| | | ></el-option> |
| | | </el-select> --> |
| | | </div> |
| | | |
| | | <div class="flex-column"> |
| | | <el-button @click="addConditionBranch" class="w-fit mt-3" type="success">添加分支</el-button> |
| | | </div> |
| | | <Handle :id="otherHandleId" type="source" :position="Position.Right" /> |
| | | </div> |
| | | <el-button v-if="!isViewMode" class="w-fit mt-3" type="primary" @click="addConditionItem(item)">添加条件</el-button> |
| | | </div> |
| | | </div> |
| | | <!-- <Handle :id="handleId" type="source" :position="Position.Right" /> --> |
| | | </div> |
| | | |
| | | <!-- <div> |
| | | <span>起始</span> |
| | | |
| | | <Handle type="source" :position="Position.Right" /> |
| | | </div> --> |
| | | <div v-else-if="isViewMode" class="h-[24px]"></div> |
| | | <el-button v-else-if="!isViewMode" @click="addConditionBranch" class="w-fit mt-3" type="success">添加分支</el-button> |
| | | <Handle class="!right-0 !-translate-y-4" :id="item.id" type="source" :position="Position.Right" /> |
| | | </FieldLayout> |
| | | </NodeBasicLayout> |
| | | </template> |
| | | |
| | | <script lang="ts" setup> |
| | | import { Handle, Position, useNode, useVueFlow } from '@vue-flow/core'; |
| | | import { ref, watchEffect } from 'vue'; |
| | | |
| | | import type { NodeProps } from '@vue-flow/core'; |
| | | import { computed } from 'vue'; |
| | | import { VueFlowConstant } from '../../VueFlowConstant'; |
| | | import { Handle, Position, useNode, useVueFlow } from '@vue-flow/core'; |
| | | import { computed, ref, watchEffect } from 'vue'; |
| | | import { ConditionHelper, VueFlowHelper } from '../../VueFlowHelper'; |
| | | import { compareOperationMap, VarType, conditionOperatorMap, varTypeMap } from '../../vueFlowEnum'; |
| | | import { LLMNodeData, LLMNodeEvents } from './index'; |
| | | import { deepClone } from '/@/utils/other'; |
| | | defineProps<NodeProps<LLMNodeData, LLMNodeEvents>>(); |
| | | import { CompareOperation, NodeType, VarType, compareOperationMap, conditionOperatorMap } from '../../vueFlowEnum'; |
| | | import type { LLMNodeData, LLMNodeEvents } from './index'; |
| | | |
| | | import FieldLayout from './components/FieldLayout.vue'; |
| | | import NodeBasicLayout from './components/NodeBasicLayout.vue'; |
| | | defineProps< |
| | | NodeProps<LLMNodeData, LLMNodeEvents> & { |
| | | isViewMode?: boolean; |
| | | } |
| | | >(); |
| | | const node = useNode(); |
| | | const leftId = VueFlowHelper.getHandleId(node, 'target'); |
| | | const { findNode } = useVueFlow(); |
| | | const referenceOptions = ref([]); |
| | | const otherHandleId = VueFlowHelper.genId(); |
| | | |
| | | const isShowRight = (item) => { |
| | | const yes = ![CompareOperation.empty, CompareOperation.notEmpty].includes(item.comparison_operation); |
| | | return yes; |
| | | }; |
| | | |
| | | const treeReferOptions = computed(() => { |
| | | const result = []; |
| | | for (const item of referenceOptions.value) { |
| | |
| | | groupName: item?.data.title ?? item?.label, |
| | | options: [], |
| | | }; |
| | | const varList = VueFlowHelper.getFieldValue(item.data,'var_list'); |
| | | const varList = VueFlowHelper.getFieldValue(item.data, 'var_list'); |
| | | if (varList) { |
| | | varList |
| | | .filter((item: any) => Boolean(item.name)) |
| | |
| | | }); |
| | | |
| | | const data = ref(node.node.data); |
| | | const conditionGroupList = ref(VueFlowHelper.getFieldValue(data.value,'condition')); |
| | | const titleIsEdit = ref(false); |
| | | |
| | | function handleClickAddBtn() { |
| | | if (!data.value[VueFlowConstant.GROUP_PARAMS_KEY]) { |
| | | data.value[VueFlowConstant.GROUP_PARAMS_KEY] = []; |
| | | } |
| | | const conditionGroupList = ref(VueFlowHelper.getFieldValue(data.value, 'condition')); |
| | | |
| | | data.value[VueFlowConstant.GROUP_PARAMS_KEY].push({ |
| | | name: '', |
| | | description: '', |
| | | type: '', |
| | | isRequired: true, |
| | | }); |
| | | } |
| | | const { removeEdges } = useVueFlow(); |
| | | |
| | | function handleClickDeleteBtn(index: number) { |
| | | data.value[VueFlowConstant.GROUP_PARAMS_KEY].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); |
| | | const removeRelativeHandleEdge = (handleId: string) => { |
| | | const edges = node.connectedEdges.value.filter((item) => item.sourceHandle === handleId || item.targetHandle === handleId); |
| | | removeEdges(edges); |
| | | }; |
| | | |
| | | const addConditionBranch = () => { |
| | | const conditionGroup = ConditionHelper.getDefaultConditionGroup(); |
| | | conditionGroupList.value.push(conditionGroup); |
| | | // 不能删除其他分支 |
| | | conditionGroupList.value.splice(-1, 0, conditionGroup); |
| | | }; |
| | | |
| | | const delConditionBranch = (index) => { |
| | | const group = conditionGroupList.value[index]; |
| | | |
| | | conditionGroupList.value.splice(index, 1); |
| | | removeRelativeHandleEdge(group.id); |
| | | if (conditionGroupList.value.length === 0) { |
| | | addConditionBranch(); |
| | | } |