From df0a461ea2018f99ccbc82148f8ae3f6cddaf23b Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期四, 19 十二月 2024 16:49:02 +0800
Subject: [PATCH] 意图分析拆分

---
 src/components/chat/hooks/useScrollLoad.ts |   94 ++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 81 insertions(+), 13 deletions(-)

diff --git a/src/components/chat/hooks/useScrollLoad.ts b/src/components/chat/hooks/useScrollLoad.ts
index 7cd7fe6..a9fbb78 100644
--- a/src/components/chat/hooks/useScrollLoad.ts
+++ b/src/components/chat/hooks/useScrollLoad.ts
@@ -1,8 +1,12 @@
 import moment from 'moment';
-import { Ref, ShallowRef, computed, nextTick, onBeforeUnmount, ref, unref } from 'vue';
+import type { Ref, ShallowRef } from 'vue';
+import { computed, nextTick, onBeforeUnmount, ref, unref } from 'vue';
 import { LOAD_CHAT_LIMIT } from '../constants';
-import { AnswerType, ChatContent, ChatMessage, RoleEnum, StepEnum, StepItem } from '../model/types';
-import { GetHistoryAnswer, QueryHistoryDetail } from '/@/api/ai/chat';
+import type { ChatContent, ChatMessage, StepItem } from '../model/types';
+import { AnswerType, MultiChatType, RoleEnum, StepEnum } 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>;
@@ -20,14 +24,29 @@
 	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
@@ -65,6 +84,7 @@
 					type: AnswerType.Text,
 					values: item.question,
 				},
+				isChecked: false,
 			} as ChatMessage;
 		});
 		const resList = await Promise.all(
@@ -78,7 +98,6 @@
 			const insertIndex = index + 1 + i;
 			const currentUserMsg = tmpMessageList[insertIndex - 1];
 			currentUserMsg.content.values = item?.answer?.question ?? currentUserMsg.content.values;
-		
 
 			const mapUser = userItemIdMap.get(item.answer?.history_id);
 
@@ -91,12 +110,18 @@
 					: {
 							historyId: item.answer?.history_id,
 							role: RoleEnum.assistant,
-							content: parseAnswerContent(item.answer),
+							content: parseAnswerContent(item?.answer),
 							state: item.answer_state,
 							sectionAId: mapUser?.section_a_id,
 							createTime: answerTime,
-							stepList: convertProcessToStep(item?.answer?.exec_process),
-							stepIsShow:false
+							isStopMsg: false,
+							stepGroup: (item?.answer?.reports ?? []).map((item) => ({
+								value: convertProcessToStep(item?.exec_process),
+								isShow: false,
+							})),
+
+							conclusion: item?.answer?.conclusion ?? [],
+							isChecked: false,
 					  }
 			);
 			i++;
@@ -106,9 +131,52 @@
 	};
 
 	/**
+	 * 鍔犺浇鍒嗕韩鏁版嵁
+	 */
+	const loadShareData = async () => {
+		const res = await getShareChatJsonByPost({
+			share_id: router.currentRoute.value.query.id as string,
+		});
+
+		const msgValue = res?.values;
+		if (!msgValue) {
+			messageList.value = [];
+			return;
+		}
+		const userMsg: ChatMessage = {
+			historyId: msgValue.history_id,
+			role: RoleEnum.user,
+			content: {
+				type: AnswerType.Text,
+				values: msgValue.question,
+			},
+			isChecked: false,
+		};
+
+		const assistantMsg: ChatMessage = {
+			historyId: msgValue.history_id,
+			role: RoleEnum.assistant,
+			content: parseAnswerContent(msgValue),
+			stepGroup: (msgValue?.reports ?? []).map((item) => ({
+				value: convertProcessToStep(item?.exec_process),
+				isShow: false,
+			})),
+			isStopMsg: false,
+
+			conclusion: msgValue.conclusion ?? [],
+			isChecked: false,
+		};
+		messageList.value = [userMsg, assistantMsg];
+	};
+
+	/**
 	 * 鍔犺浇婊氬姩鑼冨洿鏁版嵁
 	 */
 	const loadRangeData = async (lastEnd = nextUserMsgEndIndex.value) => {
+		if (isSharePage.value) {
+			await loadShareData();
+			return;
+		}
 		const res = await QueryHistoryDetail({
 			history_group_id: unref(historyGroupId),
 			last_end: lastEnd,
@@ -137,7 +205,7 @@
 				return;
 			}
 
-			let h1 = container.value.scrollHeight;
+			const h1 = container.value.scrollHeight;
 			moreIsLoading.value = true;
 			await loadRangeData(nextUserMsgEndIndex.value).finally(() => {
 				moreIsLoading.value = false;
@@ -146,7 +214,7 @@
 			nextTick(() => {
 				nextTick(() => {
 					nextTick(() => {
-						let h2 = container.value.scrollHeight;
+						const h2 = container.value.scrollHeight;
 						container.value.scrollTo({
 							//椤堕儴鍦ㄥ師鍏堝熀纭�涓婂線涓嬫粴鍔�50px锛岄湶鍑烘柊鍔犺浇鏁版嵁鐨勪竴鐐�
 							// top: h2 - h1 - 50,

--
Gitblit v1.9.3