From 768a63bdae68f9440d4b7f5768c3ea7f9308f2ab Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期三, 06 十一月 2024 14:08:58 +0800
Subject: [PATCH] 流更改

---
 src/components/chat/Chat.vue |   69 +++++++++++++++++++++++++---------
 1 files changed, 51 insertions(+), 18 deletions(-)

diff --git a/src/components/chat/Chat.vue b/src/components/chat/Chat.vue
index 0f01e32..05b6846 100644
--- a/src/components/chat/Chat.vue
+++ b/src/components/chat/Chat.vue
@@ -10,7 +10,7 @@
 					<div
 						class="group flex px-4 py-6 hover:bg-slate-100 rounded-lg relative"
 						:class="{ 'flex-row-reverse': item.role === RoleEnum.user }"
-						v-for="(item, index) of computedMessageList"
+						v-for="(item, msgIndex) of computedMessageList"
 						:key="`${item.historyId}_${item.role}`"
 					>
 						<div class="absolute top-0 left-[72px] text-[#8d8e99]">{{ item?.createTime }}</div>
@@ -51,7 +51,7 @@
 												>
 													<template
 														#icon
-														v-if="index + 1 === item.stepList.length && isTalking && index === computedMessageList.length - 1"
+														v-if="index + 1 === item.stepList.length && isTalking && msgIndex === computedMessageList.length - 1"
 													>
 														<span class="ywifont ywicon-loading1 animate-spin !text-[24px]"></span>
 													</template>
@@ -84,7 +84,12 @@
 												</div>
 											</div>
 											<template v-else>
-												<component :is="answerTypeMapCom[item.content.type]" :data="item.content.values" :originData="item" />
+												<component
+													:conclusion="item.conclusion"
+													:is="answerTypeMapCom[item.content.type]"
+													:data="item.content.values"
+													:originData="item"
+												/>
 												<div
 													v-if="item.role === RoleEnum.assistant && item.content.origin?.ext_call_list"
 													class="flex font-bold items-center mt-6"
@@ -109,12 +114,12 @@
 										v-if="item.role === RoleEnum.user && item.content?.values"
 										class="absolute flex items-center right-0 mr-4 space-x-2"
 									>
-										<!-- <div class="flex items-center justify-center size-[20px]">
+										<div class="flex items-center justify-center size-[20px]">
 											<i
 												class="p-2 ywifont ywicon-copy cursor-pointer hover:text-[#0284ff] font-medium !text-[15px] hover:!text-[18px]"
 												@click="copyUserClick(item)"
 											/>
-										</div> -->
+										</div>
 										<div class="flex items-center justify-center size-[20px]">
 											<i
 												class="p-2 ywifont ywicon-cubelifangti cursor-pointer hover:text-[#0284ff] text-[#000] font-[590] !text-[15px] hover:!text-[18px]"
@@ -241,6 +246,8 @@
 	roomConfig,
 } from '/@/stores/chatRoom';
 import { ErrorCode } from '/@/utils/request';
+import { ElMessage } from 'element-plus';
+import useClipboard from 'vue-clipboard3';
 const chatWidth = '75%';
 const voicePageIsShow = ref(false);
 let isTalking = ref(false);
@@ -410,20 +417,42 @@
 	// queryProcess();
 	resetStep();
 	let res = null;
-	await questionStreamByPost(params, (chunkRes) => {
-		Logger.info('chunk response锛歕n\n' + JSON.stringify(chunkRes));
-		if (chunkRes.mode === 'result') {
-			res = chunkRes.value;
-		} else {
+	
+	const resultP = new Promise(async (resolve, reject) => {
+		await questionStreamByPost(params, (chunkRes) => {
+			Logger.info('chunk response锛歕n\n' + JSON.stringify(chunkRes));
+			if (chunkRes.mode === 'result') {
+				res = chunkRes.value;
+				resolve(res);
+				chunkRes.value = '鍑嗗鏁版嵁鍒嗘瀽';
+			}
+
+			if (chunkRes.mode === 'conclusion') {
+				computedMessageList.value.at(-1).conclusion = chunkRes.value;
+				chunkRes.value = '鍒嗘瀽缁撴潫';
+			}
+
+			if (chunkRes.mode === 'finish') {
+				isTalking.value = false;
+				return;
+			}
+
 			const stepItem = convertProcessItem(chunkRes);
 			computedMessageList.value.at(-1).stepList.push(stepItem);
 			scrollToBottom();
-		}
-	}).finally(() => {
-		computedMessageList.value.at(-1).stepIsShow = false;
-		resetStep();
+		})
+			.catch((err) => {
+				throw err;
+			})
+			.finally(() => {
+				isTalking.value = false;
+
+				computedMessageList.value.at(-1).stepIsShow = false;
+				resetStep();
+			});
 	});
-	questionRes = res;
+
+	questionRes = await resultP;
 	const content = parseContent(res);
 	return content;
 };
@@ -500,8 +529,6 @@
 		// 	type: AnswerType.Text,
 		// 	values: '鍙戠敓閿欒锛�',
 		// });
-	} finally {
-		isTalking.value = false;
 	}
 };
 
@@ -631,8 +658,14 @@
 //#endregion
 //#region ====================== 鐢ㄦ埛璇㈤棶鐨勯棶棰樿缃负甯哥敤璇� ======================
 const setCommonQuestionInfo = ref({});
+const { toClipboard } = useClipboard();
+
 //鐢ㄦ埛澶嶅埗闂
-const copyUserClick = () => {};
+const copyUserClick = (item) => {
+	const text = item.content.values;
+	ElMessage.success('澶嶅埗鎴愬姛');
+	toClipboard(text);
+};
 //鐢ㄦ埛闂璁剧疆涓哄父鐢ㄨ
 const setCommonQuestionClick = (item) => {
 	setCommonQuestionInfo.value = item;

--
Gitblit v1.9.3