From 20c1c4455912a19878404b6b5733475db6eadfb8 Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期一, 02 十二月 2024 17:47:33 +0800
Subject: [PATCH] 停止生成

---
 src/components/chat/hooks/useScrollLoad.ts |   71 ++++++++++++++++++++++++++++++++++-
 1 files changed, 68 insertions(+), 3 deletions(-)

diff --git a/src/components/chat/hooks/useScrollLoad.ts b/src/components/chat/hooks/useScrollLoad.ts
index 2f74288..0309fed 100644
--- a/src/components/chat/hooks/useScrollLoad.ts
+++ b/src/components/chat/hooks/useScrollLoad.ts
@@ -1,8 +1,10 @@
 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 } from '../model/types';
-import { GetHistoryAnswer, QueryHistoryDetail } from '/@/api/ai/chat';
+import { AnswerType, ChatContent, ChatMessage, 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>;
@@ -10,6 +12,24 @@
 	parseAnswerContent: (res: any) => ChatContent;
 };
 
+export const convertProcessItem = (processItem: any) => {
+	switch (processItem.mode) {
+		case 'begin':
+			break;
+		case 'end':
+			break;
+	}
+	return {
+		status: StepEnum.Success,
+		title: processItem.value,
+	};
+};
+export const convertProcessToStep = (process: any[]) => {
+	const stepList = (process ?? []).map<StepItem>((item) => {
+		return convertProcessItem(item);
+	});
+	return stepList;
+};
 /**
  * 婊氬姩鍔犺浇鏁版嵁
  * @returns
@@ -47,6 +67,7 @@
 					type: AnswerType.Text,
 					values: item.question,
 				},
+				isChecked: false,
 			} as ChatMessage;
 		});
 		const resList = await Promise.all(
@@ -61,7 +82,8 @@
 			const currentUserMsg = tmpMessageList[insertIndex - 1];
 			currentUserMsg.content.values = item?.answer?.question ?? currentUserMsg.content.values;
 
-			const mapUser = userItemIdMap.get(item.answer.history_id);
+			const mapUser = userItemIdMap.get(item.answer?.history_id);
+
 			const answerTime = formatShowTimeYear.value(mapUser?.create_time);
 			tmpMessageList.splice(
 				insertIndex,
@@ -75,6 +97,10 @@
 							state: item.answer_state,
 							sectionAId: mapUser?.section_a_id,
 							createTime: answerTime,
+							stepList: convertProcessToStep(item?.answer?.exec_process),
+							stepIsShow: false,
+							conclusion: item?.answer?.conclusion ?? [],
+							isChecked: false,
 					  }
 			);
 			i++;
@@ -84,9 +110,48 @@
 	};
 
 	/**
+	 * 鍔犺浇鍒嗕韩鏁版嵁
+	 */
+	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),
+			stepList: convertProcessToStep(msgValue.exec_process),
+			stepIsShow: 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,

--
Gitblit v1.9.3