From 8703f7ddda1cbdbee1cefc4c8f9a31ea97272494 Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期一, 18 十一月 2024 14:24:50 +0800
Subject: [PATCH] 打包优化: 1)使用 lodash-es 2)element-plus按需导入

---
 src/components/chat/hooks/useScrollLoad.ts |   55 ++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 48 insertions(+), 7 deletions(-)

diff --git a/src/components/chat/hooks/useScrollLoad.ts b/src/components/chat/hooks/useScrollLoad.ts
index 3666dcd..0309fed 100644
--- a/src/components/chat/hooks/useScrollLoad.ts
+++ b/src/components/chat/hooks/useScrollLoad.ts
@@ -2,7 +2,9 @@
 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 { GetHistoryAnswer, QueryHistoryDetail } from '/@/api/ai/chat';
+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>;
@@ -23,7 +25,7 @@
 	};
 };
 export const convertProcessToStep = (process: any[]) => {
-	const stepList = (process??[]).map<StepItem>((item) => {
+	const stepList = (process ?? []).map<StepItem>((item) => {
 		return convertProcessItem(item);
 	});
 	return stepList;
@@ -65,7 +67,7 @@
 					type: AnswerType.Text,
 					values: item.question,
 				},
-				isChecked:false,
+				isChecked: false,
 			} as ChatMessage;
 		});
 		const resList = await Promise.all(
@@ -79,7 +81,7 @@
 			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);
 
 			const answerTime = formatShowTimeYear.value(mapUser?.create_time);
@@ -96,9 +98,9 @@
 							sectionAId: mapUser?.section_a_id,
 							createTime: answerTime,
 							stepList: convertProcessToStep(item?.answer?.exec_process),
-							stepIsShow:false,
-							conclusion:item?.answer?.conclusion ??[],
-							isChecked:false,
+							stepIsShow: false,
+							conclusion: item?.answer?.conclusion ?? [],
+							isChecked: false,
 					  }
 			);
 			i++;
@@ -108,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