From a313d2b6c11b75234d7ad7e9d0963ca17ada5930 Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期四, 16 一月 2025 18:07:58 +0800
Subject: [PATCH] Merge branch 'test' of http://47.103.154.90:83/r/WI/Web.V1.0 into test

---
 src/components/chat/Chat.vue |  176 +++++++++++++++-------------------------------------------
 1 files changed, 47 insertions(+), 129 deletions(-)

diff --git a/src/components/chat/Chat.vue b/src/components/chat/Chat.vue
index f3f8915..3fbb0e4 100644
--- a/src/components/chat/Chat.vue
+++ b/src/components/chat/Chat.vue
@@ -1,11 +1,5 @@
 <template>
-	<ChatContainer
-		:loading="chatListLoading"
-		:more-is-loading="moreIsLoading"
-		:is-share-page="isSharePage"
-		:chat-width="chatWidth"
-		ref="containerRef"
-	>
+	<ChatContainer :loading="chatListLoading" :more-is-loading="moreIsLoading" :is-share-page="isSharePage" ref="containerRef">
 		<!-- 娑堟伅鍒楄〃 -->
 		<template #message-list>
 			<MessageList
@@ -15,6 +9,7 @@
 				@shareClick="shareClick"
 				@setCommonQuestionClick="setCommonPhraseClick"
 				@sendChatMessage="sendChatMessage"
+				@stopGenClick="stopGenClick"
 				@askMoreClick="askMoreClick"
 			/>
 			<el-empty v-else-if="isSharePage && !chatListLoading" :image-size="200">
@@ -54,7 +49,7 @@
 import moment from 'moment';
 import { computed, onActivated, onMounted, ref } from 'vue';
 import { loadAmisSource } from '../amis/load';
-import { convertProcessItem, convertProcessToStep, formatShowTimeYear, useScrollLoad } from './hooks/useScrollLoad';
+import { useScrollLoad } from './hooks/useScrollLoad';
 import type { ChatContent } from './model/types';
 import { AnswerState, AnswerType, RoleEnum, type ChatMessage } from './model/types';
 import { getShareChatJsonByPost, questionStreamByPost } from '/@/api/ai/chat';
@@ -79,12 +74,17 @@
 import emitter from '/@/utils/mitt';
 import { useCompRef } from '/@/utils/types';
 import { toMyFixed } from '/@/utils/util';
+import { useLoadData } from './hooks/useLoadData';
+import { useSyncMsg } from './hooks/useSyncMsg';
 const containerRef = useCompRef(ChatContainer);
 const chatListDom = computed(() => containerRef.value?.chatListDom);
-const chatWidth = '75%';
+const scrollToBottom = () => {
+	containerRef.value?.scrollToBottom();
+};
+const { loadReplyData, parseContent, parseExtraContent, convertProcessItem, convertProcessToStep, formatShowTimeYear } = useLoadData();
 const voicePageIsShow = ref(false);
 let isTalking = ref(false);
-
+const chatWidth = computed(() => containerRef.value?.chatWidth);
 let messageContent = ref<ChatContent>({
 	type: AnswerType.Text,
 	values: '',
@@ -96,111 +96,6 @@
 const computedMessageList = computed(() => {
 	return messageList.value.filter((v) => !!v);
 });
-
-const parseExtraContent = (res) => {
-	if (!res) return {};
-	const askMoreList = orderBy(res.context_history, [(item) => Number(item.radio)], ['desc']);
-	const errCode = res?.err_code;
-	const errMsg = res?.json_msg;
-	const origin = res;
-
-	return {
-		askMoreList,
-		errCode,
-		errMsg,
-		origin,
-	};
-};
-
-const parseContent = (res, reportIsShow = false, extraContent?) => {
-	if (!res) return null;
-	let content: ChatContent = {
-		type: AnswerType.Text,
-		values: '瑙f瀽澶辫触锛�',
-	};
-	if (res.type) {
-		res.answer_type = res.type;
-	}
-	const curExtraContent = parseExtraContent(res);
-
-	switch (res.answer_type) {
-		case AnswerType.RecordSet:
-			content = {
-				type: AnswerType.RecordSet,
-				values: res.values,
-			};
-			break;
-		case AnswerType.Text:
-			content = {
-				type: AnswerType.Text,
-				values: res.values ?? res.answer,
-			};
-			break;
-		case AnswerType.Script:
-			content = {
-				type: AnswerType.Script,
-				values: res,
-			};
-			break;
-
-		case AnswerType.Knowledge:
-			content = {
-				type: AnswerType.Knowledge,
-				values: res.knowledge,
-			};
-
-			break;
-		case AnswerType.Report:
-			content = {
-				type: AnswerType.Report,
-				values: (res?.reports ?? []).map((item) => ({
-					content: parseContent(item, reportIsShow, { origin: item, conclusion: item.conclusion ?? [] }),
-				})),
-			};
-			break;
-
-		case AnswerType.Summary:
-			content = {
-				type: AnswerType.Summary,
-				values: res.summary?.map((item) => {
-					item.reportIsShow = reportIsShow;
-					return item;
-				}),
-			};
-			break;
-		case AnswerType.Url:
-			content = {
-				type: AnswerType.Url,
-				values: res.url,
-			};
-			break;
-		case AnswerType.Map:
-			content = {
-				type: AnswerType.Map,
-				values: res.values,
-			};
-			break;
-		default:
-			content = {
-				type: AnswerType.Text,
-				values: '瑙f瀽澶辫触锛�',
-			};
-			break;
-	}
-	if (!extraContent) {
-		content = {
-			...content,
-			...curExtraContent,
-		};
-	} else {
-		content = {
-			...content,
-			...extraContent,
-		};
-	}
-
-	return content;
-};
 
 let questionRes = null;
 let position = null;
@@ -340,14 +235,29 @@
 						chunkRes.value = '鍒嗘瀽缁撴潫';
 					}
 				}
+				const getLastGroup = () => {
+					const lastGroup = computedMessageList.value.at(-1).stepGroup.at(-1);
+					return lastGroup;
+				};
+				const getLastStepList = () => {
+					const stepList = getLastGroup()?.value ?? [];
+					return stepList;
+				};
+				const getLastStepItem = () => {
+					const stepList = getLastStepList();
+					const lastStepItem = stepList.at(-1);
+					return lastStepItem;
+				};
+
+				const checkStepItem = (stepItem) => {
+					if (!stepItem.subStep) {
+						stepItem.subStep = [];
+					}
+				};
 
 				if (chunkRes.mode === 'question') {
-					const lastGroup = computedMessageList.value.at(-1).stepGroup.at(-1);
-					const stepList = lastGroup?.value ?? [];
-					const lastStepItem = stepList.at(-1);
-					if (!lastStepItem.subStep) {
-						lastStepItem.subStep = [];
-					}
+					const lastStepItem = getLastStepItem();
+					checkStepItem(lastStepItem);
 					lastStepItem.subStep.push({
 						type: chunkRes.value.type,
 						data: chunkRes.value,
@@ -355,6 +265,7 @@
 					scrollToBottom();
 					return;
 				}
+
 				// 鏆傛椂涓嶈�冭檻澶氫釜 report鎯呭喌
 
 				// if (lastIsResult && chunkRes.mode !== 'finish') {
@@ -493,9 +404,11 @@
 		updateLoadIndex();
 
 		userItem.historyId = questionRes?.history_id;
+		const current = moment().format('YYYY-MM-DD HH:mm:ss');
+		userItem.createTime = current;
 		userItem.content.values = questionRes?.question ?? userItem.content.values;
 		assistantItem.historyId = questionRes?.history_id;
-		const currentTime = formatShowTimeYear(moment().format('YYYY-MM-DD HH:mm:ss'));
+		const currentTime = formatShowTimeYear(current);
 		assistantItem.createTime = currentTime;
 		assistantItem.content = resMsgContent;
 		setTimeout(() => {
@@ -513,9 +426,18 @@
 	container: chatListDom,
 	historyGroupId: currentRouteId,
 	messageList,
-	parseAnswerContent: parseContent,
+	loadReplyData,
 });
-
+useSyncMsg({
+	msgList: messageList,
+	updateLoadIndex,
+	historyGroupId: currentRouteId,
+	checkCanSync: (data) => {
+		return !isTalking.value && !moreIsLoading.value;
+	},
+	loadReplyData,
+	scrollToBottom,
+});
 const chatListLoading = ref(true);
 
 onActivated(() => {
@@ -529,9 +451,7 @@
 	};
 	sendChatMessage();
 };
-const scrollToBottom = () => {
-	containerRef.value?.scrollToBottom();
-};
+
 
 const initHistoryChat = () => {
 	// 鍒濆鐘舵�佹粴涓�涓�
@@ -608,8 +528,6 @@
 	}
 	loadAmisSource();
 });
-
-
 
 const askMoreClick = (item) => {
 	if (!item.question) return;

--
Gitblit v1.9.3