From 1711b75cf4e9f706be461c2be82edf760b28d3bd Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期五, 08 十一月 2024 16:06:41 +0800
Subject: [PATCH] disabled

---
 src/components/chat/hooks/useScrollLoad.ts |  104 ++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 88 insertions(+), 16 deletions(-)

diff --git a/src/components/chat/hooks/useScrollLoad.ts b/src/components/chat/hooks/useScrollLoad.ts
index 457bfc1..0309fed 100644
--- a/src/components/chat/hooks/useScrollLoad.ts
+++ b/src/components/chat/hooks/useScrollLoad.ts
@@ -1,8 +1,10 @@
-import { Ref, ShallowRef, nextTick, onBeforeUnmount, ref, unref } from 'vue';
+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
@@ -28,12 +48,17 @@
 			history_id: historyId,
 		});
 	};
-
+	const formatShowTimeYear = computed(() => {
+		return (str) => {
+			return moment(str).format('MM鏈圖D鏃� HH:mm:ss');
+		};
+	});
 	/**
 	 * 鑾峰彇鐢ㄦ埛鍥炲鏁版嵁锛屽苟鎻掑叆鍒板璇濆綋涓幓
 	 */
 	const loadReplyData = async (userMsg: any[]) => {
-		const sectionAIdMap = new Map();
+		const userItemIdMap = new Map();
+		// 鐢ㄦ埛娑堟伅
 		const tmpMessageList: ChatMessage[] = userMsg.map((item) => {
 			return {
 				historyId: item.history_id,
@@ -42,11 +67,12 @@
 					type: AnswerType.Text,
 					values: item.question,
 				},
+				isChecked: false,
 			} as ChatMessage;
 		});
 		const resList = await Promise.all(
 			(userMsg ?? []).map((item) => {
-				sectionAIdMap.set(item.history_id, item.section_a_id);
+				userItemIdMap.set(item.history_id, item);
 				return getAnswerById(item.history_id);
 			})
 		);
@@ -55,6 +81,10 @@
 			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);
 			tmpMessageList.splice(
 				insertIndex,
 				0,
@@ -65,7 +95,12 @@
 							role: RoleEnum.assistant,
 							content: parseAnswerContent(item.answer),
 							state: item.answer_state,
-							sectionAId: sectionAIdMap.get(item.answer.history_id),
+							sectionAId: mapUser?.section_a_id,
+							createTime: answerTime,
+							stepList: convertProcessToStep(item?.answer?.exec_process),
+							stepIsShow: false,
+							conclusion: item?.answer?.conclusion ?? [],
+							isChecked: false,
 					  }
 			);
 			i++;
@@ -75,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,
@@ -97,7 +171,6 @@
 	//婊氬姩鐩戝惉
 	async function onChatListScroll() {
 		if (container.value.scrollTop == 0) {
-
 			// 鏇村鏁版嵁姝e湪鍔犺浇鏃�
 			if (moreIsLoading.value) {
 				return;
@@ -113,9 +186,9 @@
 				moreIsLoading.value = false;
 			});
 			//鏇存柊鍚庯紝绛夊緟椤甸潰娓叉煋瀹屾瘯鍐嶅幓鎷縮crollHeight,鍚﹀垯鎷垮埌鐨勬槸涔嬪墠鐨�
-			nextTick(()=>{
-				nextTick(()=>{
-					nextTick(()=>{
+			nextTick(() => {
+				nextTick(() => {
+					nextTick(() => {
 						let h2 = container.value.scrollHeight;
 						container.value.scrollTo({
 							//椤堕儴鍦ㄥ師鍏堝熀纭�涓婂線涓嬫粴鍔�50px锛岄湶鍑烘柊鍔犺浇鏁版嵁鐨勪竴鐐�
@@ -123,10 +196,9 @@
 							top: h2 - h1,
 							behavior: 'instant', //auto-鑷姩婊氬姩 instant-鐬棿婊氬姩 smooth-骞虫粦婊氬姩
 						});
-					})
-				})
-			})
-
+					});
+				});
+			});
 		}
 	}
 

--
Gitblit v1.9.3