From 890adec7fddfe9d5f5da4511343ac6e8341d46b3 Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期一, 16 十二月 2024 10:34:41 +0800
Subject: [PATCH] 可改变大小

---
 src/components/vue-flow/ui/nodes/OutputNode.vue |  203 ++++++++++++++++++++++----------------------------
 1 files changed, 89 insertions(+), 114 deletions(-)

diff --git a/src/components/vue-flow/ui/nodes/OutputNode.vue b/src/components/vue-flow/ui/nodes/OutputNode.vue
index 8c355f4..9799f76 100644
--- a/src/components/vue-flow/ui/nodes/OutputNode.vue
+++ b/src/components/vue-flow/ui/nodes/OutputNode.vue
@@ -1,117 +1,90 @@
 <template>
-	<div
-		class="min-w-[320px] 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
+		:maxWidth="520"
+		v-model:title="data.title"
+		:type="NodeType.Output"
+		:description="
+			VueFlowHelper.getConfigValue(
+				data,
+				'description',
+				'鍙悜鐢ㄦ埛鍙戦�佹秷鎭紝骞朵笖鏀寔杩涜鏇翠赴瀵岀殑浜や簰锛屼緥濡傝姹傜敤鎴锋壒鍑嗚繘琛屾煇椤规晱鎰熸搷浣溿�佸厑璁哥敤鎴峰湪妯″瀷杈撳嚭鍐呭鐨勫熀纭�涓婄洿鎺ヤ慨鏀瑰苟鎻愪氦銆�'
+			)
+		"
 	>
-		<Handle :id="targetHandleId" type="source" :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"
-		>
-			<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="false" v-else v-model="data.title" @blur="() => (titleIsEdit = false)"></el-input>
-					</div>
-				</div>
-			</div>
+		<Handle :id="targetHandleId" type="target" :position="Position.Left" />
+		<FieldLayout level="2" :title="VueFlowHelper.getParams(outputParams, 'output_msg').label">
+			<el-input
+				v-model="VueFlowHelper.getParams(outputParams, 'output_msg').value.msg"
+				type="textarea"
+				:autosize="{ minRows: 4, maxRows: 6 }"
+				:placeholder="VueFlowHelper.getParams(outputParams, 'output_msg').placeholder"
+				autocomplete="off"
+			>
+			</el-input>
+		</FieldLayout>
+		<FieldLayout level="2" :title="VueFlowHelper.getParams(outputParams, 'output_result').label">
+			<el-radio-group v-model="VueFlowHelper.getParams(outputParams, 'output_result').value.type" @change="interactionTypeChange">
+				<el-radio v-for="item in Object.keys(interactionTypeMap)" :key="item" :value="item">{{ interactionTypeMap[item] }}</el-radio>
+			</el-radio-group>
+			<el-input
+				v-model="VueFlowHelper.getParams(outputParams, 'output_result').value.value"
+				type="textarea"
+				:autosize="{ minRows: 4, maxRows: 6 }"
+				v-if="VueFlowHelper.getParams(outputParams, 'output_result').value.type === InteractionType.Input"
+			>
+			</el-input>
 
-			<div class="flex-auto gap-y-2 flex-col flex nodrag w-full">
-				<!-- <div class="text-lg font-bold">鎻愮ず璇�</div> -->
-
-				<div class="flex-column gap-y-1.5 w-full">
-					<span class="self-start text-gray-500">{{ VueFlowHelper.getParams(outputParams, 'output_msg').label }}</span>
-					<el-input
-						v-model="VueFlowHelper.getParams(outputParams, 'output_msg').value.msg"
-						type="textarea"
-						:rows="4"
-						:placeholder="VueFlowHelper.getParams(outputParams, 'output_msg').placeholder"
-						autocomplete="off"
-					>
-					</el-input>
-				</div>
-				<div class="flex-column gap-y-1.5 w-full">
-					<span class="self-start text-gray-500">{{ VueFlowHelper.getParams(outputParams, 'output_result').label }}</span>
-
-					<el-radio-group v-model="VueFlowHelper.getParams(outputParams, 'output_result').value.type">
-						<el-radio v-for="item in Object.keys(interactionTypeMap)" :key="item" :value="item">{{
-							interactionTypeMap[item]
-						}}</el-radio>
-					</el-radio-group>
-					<el-input
-						v-model="VueFlowHelper.getParams(outputParams, 'output_result').value.value"
-						type="textarea"
-						:rows="4"
-						v-if="VueFlowHelper.getParams(outputParams, 'output_result').value.type === InteractionType.Input"
-					>
-					</el-input>
-
+			<div
+				class="self-start w-full flex-col flex items-start gap-2"
+				v-else-if="VueFlowHelper.getParams(outputParams, 'output_result').value.type === InteractionType.Select"
+			>
+				<div class="flex-column gap-2">
 					<div
-						class="self-start w-full flex-col flex items-start gap-2"
-						v-else-if="VueFlowHelper.getParams(outputParams, 'output_result').value.type === InteractionType.Select"
+						class="text-gray-400 cursor-not-allowed border border-solid rounded-lg border-gray-300 py-3 pl-3 pr-2 items-center justify-between flex group/option relative mr-6"
+						:key="item.id"
+						v-for="(item, index) in VueFlowHelper.getParams(outputParams, 'output_result').options"
 					>
-						<div class="flex-column gap-2">
-							<div
-								class="text-gray-400 cursor-not-allowed border border-solid rounded-lg border-gray-300 py-3 pl-3 pr-2 items-center justify-between flex group/option relative"
-								:key="item.id"
-								v-for="(item, index) in VueFlowHelper.getParams(outputParams, 'output_result').options"
-							>
-								<span>{{ item.label }}</span>
-								<span
-									@click="delOption(index)"
-									class="cursor-pointer group-hover/option:visible invisible ywifont ywicon-shanchu text-red-500"
-								></span>
-							</div>
-						</div>
-
-						<div v-if="isEditStatus" class="flex-items-center w-full">
-							<el-input class="flex-auto" v-model="tmpEditValue"></el-input>
-							<el-button class="flex-0 ml-2" type="success" @click="confirmClick">纭畾 </el-button>
-						</div>
-						<el-button v-else type="primary" @click="addOptionClick">娣诲姞閫夐」</el-button>
+						<span>{{ item.label }}</span>
+						<span
+							@click="delOption(index)"
+							class="cursor-pointer group-hover/option:visible invisible ywifont ywicon-shanchu text-red-500"
+						></span>
+						<Handle class="absolute !-right-4" :id="item.id" type="source" :position="Position.Right" />
 					</div>
 				</div>
+
+				<div v-if="isEditStatus" class="flex-items-center w-full">
+					<el-input class="flex-auto" v-model="tmpEditValue"></el-input>
+					<el-button class="flex-0 ml-2" type="success" @click="confirmClick">纭畾 </el-button>
+				</div>
+				<el-button v-else type="primary" @click="addOptionClick">娣诲姞閫夐」</el-button>
 			</div>
-		</div>
-		<Handle v-if="VueFlowHelper.getParams(outputParams, 'output_result').value.type === InteractionType.Input ||VueFlowHelper.getParams(outputParams, 'output_result').value.type === InteractionType.None" :id="sourceHandleId" type="source" :position="Position.Right" />
-	</div>
-
-	<!-- <div>
-		<span>璧峰</span>
-
-		<Handle type="source" :position="Position.Right" />
-	</div> -->
+			<Handle
+				v-if="
+					VueFlowHelper.getParams(outputParams, 'output_result').value.type === InteractionType.Input ||
+					VueFlowHelper.getParams(outputParams, 'output_result').value.type === InteractionType.None
+				"
+				:id="sourceHandleId"
+				type="source"
+				:position="Position.Right"
+			/>
+		</FieldLayout>
+	</NodeBasicLayout>
 </template>
 
 <script lang="ts" setup>
 import { Handle, Position, useNode, useVueFlow } from '@vue-flow/core';
 import { ref } from 'vue';
+import { NodeType } from '../../vueFlowEnum';
 
 import type { NodeProps } from '@vue-flow/core';
 import { nextTick } from 'vue';
 import { VueFlowHelper } from '../../VueFlowHelper';
 import { InteractionType, interactionTypeMap } 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();
@@ -120,28 +93,10 @@
 
 const data = ref(node.node.data);
 
-const titleIsEdit = ref(false);
-
 const outputParams = ref(VueFlowHelper.getGroupParam(data.value, 0));
 
-const { removeNodes, nodes, addNodes } = useVueFlow();
+const { removeEdges } = 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 addOptionClick = () => {
 	isEditStatus.value = true;
 };
@@ -163,9 +118,29 @@
 	});
 };
 
+const removeRelativeHandleEdge = (handleId: string) => {
+	const edges = node.connectedEdges.value.filter((item) => item.sourceHandle === handleId || item.targetHandle === handleId);
+	removeEdges(edges);
+};
+
 const delOption = (index) => {
 	const options = VueFlowHelper.getParams(outputParams.value, 'output_result').options;
+	const option = options[index];
+
 	options.splice(index);
+	removeRelativeHandleEdge(option.id);
+};
+
+let preInteractionType = VueFlowHelper.getParams(outputParams.value, 'output_result').value.type;
+const interactionTypeChange = (type) => {
+	removeRelativeHandleEdge(sourceHandleId.value);
+	if (preInteractionType === InteractionType.Select) {
+		const options = VueFlowHelper.getParams(outputParams.value, 'output_result').options;
+		for (const item of options) {
+			removeRelativeHandleEdge(item.id);
+		}
+	}
+	preInteractionType = type;
 };
 
 const isEditStatus = ref(false);

--
Gitblit v1.9.3