From 9d2291d4fe44c8f3e6018103aa576fe6bfb483a9 Mon Sep 17 00:00:00 2001
From: gerson <1405270578@qq.com>
Date: 星期日, 30 六月 2024 22:03:24 +0800
Subject: [PATCH] 输入框可以输入

---
 src/views/project/ch/home/component/waterRight/top.vue   |    3 
 src/components/chat/Chat.vue                             |  142 +++++++++++++++++++++++------------------------
 src/layout/component/sidebar/waterLeftAside/asideNew.vue |   13 ++-
 src/stores/chatRoom.ts                                   |    3 +
 4 files changed, 81 insertions(+), 80 deletions(-)

diff --git a/src/components/chat/Chat.vue b/src/components/chat/Chat.vue
index 4856176..fac73b6 100644
--- a/src/components/chat/Chat.vue
+++ b/src/components/chat/Chat.vue
@@ -54,66 +54,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 = {
@@ -160,7 +100,8 @@
 const questionAi = async (text) => {
 	const res = await QuestionAi({
 		question: text,
-		section_a_id: currentSectionId,
+		// FIXME: 鏆傛椂杩欐牱
+		section_a_id: 'undefined',
 		history_group_id: activeRoomId.value,
 	});
 	// const res = {
@@ -182,6 +123,22 @@
 	return content;
 };
 
+const clearMessageContent = () =>
+	(messageContent.value = {
+		type: AnswerType.Text,
+		values: '',
+	});
+
+const scrollToBottom = () => {
+	if (!chatListDom.value) return;
+	chatListDom.value.lastElementChild?.scrollIntoView();
+};
+
+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) {
@@ -209,21 +166,60 @@
 		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: '',
-	});
-
-const scrollToBottom = () => {
-	if (!chatListDom.value) return;
-	chatListDom.value.lastElementChild?.scrollIntoView();
+	}
 };
+let currentSectionId = '';
+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,
+			};
+			console.log("馃殌 ~ activeChatRoom.value.title:", 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;
+			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,
+	}
+);
 
 watch(
 	messageList,
diff --git a/src/layout/component/sidebar/waterLeftAside/asideNew.vue b/src/layout/component/sidebar/waterLeftAside/asideNew.vue
index b48ef4e..04cb28e 100644
--- a/src/layout/component/sidebar/waterLeftAside/asideNew.vue
+++ b/src/layout/component/sidebar/waterLeftAside/asideNew.vue
@@ -100,6 +100,13 @@
 			},
 		});
 	}
+	setTimeout(() => {
+		activeRoomId.value = room.id;
+		
+	}, 0);
+	
+
+	
 };
 
 const newChatRoomClick = async () => {
@@ -117,14 +124,10 @@
 	} else {
 		chatRoomList.value.unshift(newRoom);
 	}
-	activeRoomId.value = newRoom.id;
-	nextTick(() => {
-		gotoAnswerPage(newRoom);
-	});
+	gotoAnswerPage(newRoom);
 };
 
 const roomClick = (room: ChatRoomItem) => {
-	activeRoomId.value = room.id;
 	gotoAnswerPage(room);
 };
 
diff --git a/src/stores/chatRoom.ts b/src/stores/chatRoom.ts
index 891f97d..27666f1 100644
--- a/src/stores/chatRoom.ts
+++ b/src/stores/chatRoom.ts
@@ -8,3 +8,6 @@
 
 export const activeRoomId = ref(null);
 export const activeChatRoom = computed(() => chatRoomList.value?.find((item) => item.id === activeRoomId.value));
+export const activeSampleId = ref(null);
+export const activeSectionAId= ref(null);
+export const activeLLMId= ref(null);
\ No newline at end of file
diff --git a/src/views/project/ch/home/component/waterRight/top.vue b/src/views/project/ch/home/component/waterRight/top.vue
index b08ca14..79879e4 100644
--- a/src/views/project/ch/home/component/waterRight/top.vue
+++ b/src/views/project/ch/home/component/waterRight/top.vue
@@ -31,7 +31,7 @@
 import { GetLLMList, SetLLM } from '/@/api/ai/chat';
 import PlayBar from '/@/components/chat/components/playBar/PlayBar.vue';
 import router from '/@/router';
-import { activeChatRoom } from '/@/stores/chatRoom';
+import { activeChatRoom, activeLLMId } from '/@/stores/chatRoom';
 const emits = defineEmits(['sendClick']);
 const inputValue = ref('');
 
@@ -68,7 +68,6 @@
 	activeRole: 0,
 });
 
-const activeLLMId = ref();
 const llmList = ref([]);
 const iconList = ['/static/images/wave/Glm.jpg', '/static/images/wave/Glm.jpg', '/static/images/wave/Glm.jpg'];
 const getLLMList = async () => {

--
Gitblit v1.9.3