From 1476d27514874e9c95002451a81878bd9bec8382 Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期六, 14 十二月 2024 15:36:53 +0800
Subject: [PATCH] 多轮对话

---
 src/components/chat/hooks/useScrollLoad.ts |   38 ++++++++++++++++++++++++++++++--------
 1 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/src/components/chat/hooks/useScrollLoad.ts b/src/components/chat/hooks/useScrollLoad.ts
index 7a6108f..63be29d 100644
--- a/src/components/chat/hooks/useScrollLoad.ts
+++ b/src/components/chat/hooks/useScrollLoad.ts
@@ -1,15 +1,15 @@
 import moment from 'moment';
 import { Ref, ShallowRef, computed, nextTick, onBeforeUnmount, ref, unref } from 'vue';
 import { LOAD_CHAT_LIMIT } from '../constants';
-import { AnswerType, ChatContent, ChatMessage, RoleEnum, StepEnum, StepItem } from '../model/types';
+import { AnswerType, ChatContent, ChatMessage, MultiChatType, RoleEnum, StepEnum, StepItem } from '../model/types';
 import { GetHistoryAnswer, QueryHistoryDetail, getShareChatJsonByPost } from '/@/api/ai/chat';
 import router from '/@/router';
+import { isSharePage } from '/@/stores/chatRoom';
 type UseScrollLoadOption = {
 	container: ShallowRef<HTMLDivElement>;
 	historyGroupId: string | Ref<string>;
 	messageList: Ref<ChatMessage[]>;
 	parseAnswerContent: (res: any) => ChatContent;
-	isSharePage: Ref<boolean>;
 };
 
 export const convertProcessItem = (processItem: any) => {
@@ -22,20 +22,35 @@
 	return {
 		status: StepEnum.Success,
 		title: processItem.value,
-	};
+	} as StepItem;
 };
 export const convertProcessToStep = (process: any[]) => {
-	const stepList = (process ?? []).map<StepItem>((item) => {
-		return convertProcessItem(item);
-	});
+	const stepList = (process ?? []).reduce((preVal, curVal) => {
+		if (curVal.mode === 'question') {
+			const last = preVal.at(-1);
+			if (!last.subStep) {
+				last.subStep = [];
+			}
+			const sub = {
+				data: curVal.value,
+				type: MultiChatType.Select,
+			};
+			last.subStep.push(sub);
+		} else {
+			const cur = convertProcessItem(curVal);
+			preVal.push(cur);
+		}
+		return preVal;
+	}, []);
 	return stepList;
 };
+
 /**
  * 婊氬姩鍔犺浇鏁版嵁
  * @returns
  */
 export const useScrollLoad = (option: UseScrollLoadOption) => {
-	const { container, historyGroupId, messageList, parseAnswerContent, isSharePage } = option;
+	const { container, historyGroupId, messageList, parseAnswerContent } = option;
 	const moreIsLoading = ref(false);
 
 	/** @description 涓嬫闇�瑕佸姞杞界殑鐢ㄦ埛缁撴潫绱㈠紩锛堝�掔潃鏁帮級 */
@@ -99,6 +114,8 @@
 							createTime: answerTime,
 							stepList: convertProcessToStep(item?.answer?.exec_process),
 							stepIsShow: false,
+							isStopMsg: false,
+
 							conclusion: item?.answer?.conclusion ?? [],
 							isChecked: false,
 					  }
@@ -118,7 +135,10 @@
 		});
 
 		const msgValue = res?.values;
-		if (!msgValue) return undefined;
+		if (!msgValue) {
+			messageList.value = [];
+			return;
+		}
 		const userMsg: ChatMessage = {
 			historyId: msgValue.history_id,
 			role: RoleEnum.user,
@@ -135,6 +155,8 @@
 			content: parseAnswerContent(msgValue),
 			stepList: convertProcessToStep(msgValue.exec_process),
 			stepIsShow: false,
+			isStopMsg: false,
+
 			conclusion: msgValue.conclusion ?? [],
 			isChecked: false,
 		};

--
Gitblit v1.9.3