From 4d513546eedc4738cf1b7b73425bffd4c60cc6b0 Mon Sep 17 00:00:00 2001
From: yangyin <1850366751@qq.com>
Date: 星期二, 02 七月 2024 14:02:06 +0800
Subject: [PATCH] fix: 修改成固定高度 不可有滚动条

---
 src/components/chat/Chat.vue |  177 +++++++++++++++++++++++++++++++++--------------------------
 1 files changed, 99 insertions(+), 78 deletions(-)

diff --git a/src/components/chat/Chat.vue b/src/components/chat/Chat.vue
index 4856176..930ab85 100644
--- a/src/components/chat/Chat.vue
+++ b/src/components/chat/Chat.vue
@@ -31,18 +31,16 @@
 </template>
 
 <script setup lang="ts">
-import { computed, nextTick, onMounted, ref, watch } from 'vue';
+import { ElMessage } from 'element-plus';
+import { computed, nextTick, ref, watch } from 'vue';
 import useClipboard from 'vue-clipboard3';
 import Loding from './components/Loding.vue';
-import { RecordSet } from './model/Record';
 import type { ChatContent } from './model/types';
 import { AnswerType, RoleEnum, answerTypeMapCom, roleImageMap, type ChatMessage } from './model/types';
 import { GetHistoryAnswer, QueryHistoryDetail, QuestionAi } from '/@/api/ai/chat';
 import PlayBar from '/@/components/chat/components/playBar/PlayBar.vue';
 import router from '/@/router';
-import { activeChatRoom, activeRoomId } from '/@/stores/chatRoom';
-import { ElMessage } from 'element-plus';
-import { content } from 'html2canvas/dist/types/css/property-descriptors/content';
+import { activeChatRoom, activeLLMId, activeRoomId, activeSampleId, activeSectionAId } from '/@/stores/chatRoom';
 
 let isTalking = ref(false);
 let messageContent = ref<ChatContent>({
@@ -54,66 +52,6 @@
 const computedMessageList = computed(() => {
 	return messageList.value.filter((v) => v.role !== RoleEnum.system);
 });
-// onMounted(() => {
-// 	if (!activeChatRoom.value) {
-// 		router.replace({
-// 			name: 'Home',
-// 		});
-// 		return;
-// 	}
-// 	messageContent.value = {
-// 		type: AnswerType.Text,
-// 		values: activeChatRoom.value.title,
-// 	};
-// 	sendChatMessage();
-// });
-
-const getAnswerById = async (historyId: string) => {
-	return await GetHistoryAnswer({
-		history_id: historyId,
-	});
-};
-let currentSectionId = '';
-watch(
-	() => activeRoomId.value,
-	async (val) => {
-		if (!val) {
-			router.replace({
-				name: 'Home',
-			});
-			return;
-		}
-
-		const res = await QueryHistoryDetail({
-			history_group_id: activeRoomId.value,
-		});
-		messageList.value = (res.details ?? []).map((item) => {
-			return {
-				role: RoleEnum.user,
-				content: {
-					type: AnswerType.Text,
-					values: item.question,
-				},
-			} as ChatMessage;
-		});
-		currentSectionId = res?.details?.[0]?.section_a_id;
-		const resList = await Promise.all((res.details ?? []).map((item) => getAnswerById(item.history_id)));
-		let i = 0;
-
-		resList.map((item, index) => {
-			const insertIndex = index + 1 + i;
-			messageList.value.splice(insertIndex, 0, {
-				role: RoleEnum.assistant,
-				content: parseContent(item.answer),
-			});
-			i++;
-		});
-		
-	},
-	{
-		immediate: true,
-	}
-);
 
 const parseContent = (res) => {
 	let content: ChatContent = {
@@ -158,11 +96,26 @@
 };
 
 const questionAi = async (text) => {
-	const res = await QuestionAi({
+	if (!currentSectionId) {
+		ElMessage.warning('鍙戦�佸け璐ワ紝鏈‘瀹氬簲鐢ㄥ満鏅紒');
+	}
+
+	const params = {
 		question: text,
+		// FIXME: 鏆傛椂杩欐牱
 		section_a_id: currentSectionId,
 		history_group_id: activeRoomId.value,
-	});
+	} as any;
+
+	if (currentSampleId) {
+		params.sample_id = currentSampleId;
+	}
+
+	if (currentLLMId) {
+		params.llm_id = currentLLMId;
+	}
+
+	const res = await QuestionAi(params);
 	// const res = {
 	// 	json_ok: true,
 	// 	question: '鏄ㄦ棩浜斾竴骞垮満鍘嬪姏',
@@ -182,11 +135,41 @@
 	return content;
 };
 
+const clearMessageContent = () =>
+	(messageContent.value = {
+		type: AnswerType.Text,
+		values: '',
+	});
+
+const scrollToBottom = () => {
+	if (!chatListDom.value) return;
+	chatListDom.value.lastElementChild?.scrollIntoView();
+};
+let currentSectionId = null;
+let currentSampleId = null;
+
+let currentLLMId = null;
+const getAnswerById = async (historyId: string) => {
+	return await GetHistoryAnswer({
+		history_id: historyId,
+	});
+};
 const sendChatMessage = async (content: ChatContent = messageContent.value) => {
 	if (!messageContent.value?.values) return;
 	if (activeChatRoom.value.isInitial) {
 		activeChatRoom.value.title = messageContent.value.values;
 		activeChatRoom.value.isInitial = false;
+		if (activeSampleId.value) {
+			currentSampleId = activeSampleId.value;
+		}
+
+		if (activeLLMId.value) {
+			currentLLMId = activeLLMId.value;
+		}
+
+		if (activeSectionAId.value) {
+			currentSectionId = activeSectionAId.value;
+		}
 	}
 	try {
 		isTalking.value = true;
@@ -209,21 +192,59 @@
 		isTalking.value = false;
 	}
 };
-
 const appendLastMessageContent = (content: ChatContent) => {
-	messageList.value.at(-1).content = content;
+	if (messageList.value.at(-1)) {
+		messageList.value.at(-1).content = content;
+	}
 };
 
-const clearMessageContent = () =>
-	(messageContent.value = {
-		type: AnswerType.Text,
-		values: '',
-	});
+watch(
+	() => activeRoomId.value,
+	async (val) => {
+		if (!val) {
+			router.replace({
+				name: 'Home',
+			});
+			return;
+		}
+		if (activeChatRoom.value.isInitial) {
+			messageContent.value = {
+				type: AnswerType.Text,
+				values: activeChatRoom.value.title,
+			};
+			sendChatMessage();
+		} else {
+			const res = await QueryHistoryDetail({
+				history_group_id: activeRoomId.value,
+			});
+			messageList.value = (res.details ?? []).map((item) => {
+				return {
+					role: RoleEnum.user,
+					content: {
+						type: AnswerType.Text,
+						values: item.question,
+					},
+				} as ChatMessage;
+			});
+			currentSectionId = res?.details?.[0]?.section_a_id;
+			currentSampleId = res?.details?.[0]?.sample_id;
+			const resList = await Promise.all((res.details ?? []).map((item) => getAnswerById(item.history_id)));
+			let i = 0;
 
-const scrollToBottom = () => {
-	if (!chatListDom.value) return;
-	chatListDom.value.lastElementChild?.scrollIntoView();
-};
+			resList.map((item, index) => {
+				const insertIndex = index + 1 + i;
+				messageList.value.splice(insertIndex, 0, {
+					role: RoleEnum.assistant,
+					content: parseContent(item.answer),
+				});
+				i++;
+			});
+		}
+	},
+	{
+		immediate: true,
+	}
+);
 
 watch(
 	messageList,

--
Gitblit v1.9.3