From 6e09e21b98b487621e7f19e1b91012a0e9e617ed Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期五, 21 三月 2025 13:06:26 +0800
Subject: [PATCH] 	z-index: 1;

---
 src/components/chat/hooks/useLoadData.ts |  106 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 96 insertions(+), 10 deletions(-)

diff --git a/src/components/chat/hooks/useLoadData.ts b/src/components/chat/hooks/useLoadData.ts
index d4ce2ad..1978b08 100644
--- a/src/components/chat/hooks/useLoadData.ts
+++ b/src/components/chat/hooks/useLoadData.ts
@@ -3,7 +3,13 @@
 import { AnswerType, MultiChatType, RoleEnum, StepEnum } from '../model/types';
 import { GetHistoryAnswer } from '/@/api/ai/chat';
 import moment from 'moment';
-
+import type { Attach } from '../components/playBar/hook/useAttach';
+import {
+	getFileGroupType,
+	getFileSuffix,
+	getIconByGroupType,
+	getIconClassByGroupType,
+} from '../components/playBar/hook/useUploadFile';
 export const useLoadData = () => {
 	const parseExtraContent = (res) => {
 		if (!res) return {};
@@ -108,6 +114,26 @@
 
 		return content;
 	};
+
+	/**
+	 * 鑾峰彇姝ラ缁勫垪琛�
+	 * @param reports
+	 * @returns
+	 */
+	const getStepGroupList = (reports: any[]) => {
+		const stepGroupList = (reports ?? []).map((item) => ({
+			value: convertProcessToStep(item?.exec_process),
+			isShow: false,
+		}));
+		/** @description 鍏ㄩ儴鏀惧埌绗竴涓� */
+		stepGroupList.map((item, index) => {
+			if (index !== 0) {
+				stepGroupList[0].value.push(...item.value);
+				item.value = [];
+			}
+		});
+		return stepGroupList;
+	};
 	const formatShowTimeYear = (str: string) => {
 		const date = moment(str);
 		const now = moment();
@@ -134,6 +160,48 @@
 			history_id: historyId,
 		});
 	};
+
+	const convertAttach = (userValues: any): Attach[] => {
+		const attachList: Attach[] = [];
+		if (userValues?.attach_tables) {
+			userValues.attach_tables.forEach((item: any) => {
+				attachList.push({
+					title: item.title,
+					type: 'table',
+					model: item,
+					icon: 'biaoge',
+					iconClass: 'ywicon-biaoge text-[#c5e0ff]',
+				});
+			});
+		}
+
+		if (userValues?.attach_metrics) {
+			userValues.attach_metrics.forEach((item: any) => {
+				attachList.push({
+					title: item.title,
+					type: 'metric',
+					model: item,
+					icon: 'zhibiao',
+					iconClass: 'ywicon-zhibiao text-[#c5e0ff]',
+				});
+			});
+		}
+
+		if (userValues?.attach_files) {
+			userValues.attach_files.forEach((item: any) => {
+				const suffix = getFileSuffix(item.file_name);
+				const groupType = getFileGroupType(suffix);
+				attachList.push({
+					title: item.file_name,
+					type: 'file',
+					model: item,
+					icon: getIconByGroupType(groupType),
+					iconClass: getIconClassByGroupType(groupType),
+				});
+			});
+		}
+		return attachList;
+	};
 	/**
 	 * 鑾峰彇鐢ㄦ埛鍥炲鏁版嵁锛屽苟鎻掑叆鍒板璇濆綋涓幓
 	 */
@@ -143,6 +211,7 @@
 		const tmpMessageList: ChatMessage[] = userMsg.map((item) => {
 			return {
 				historyId: item.history_id,
+				createTime: item.create_time,
 				role: RoleEnum.user,
 				content: {
 					type: AnswerType.Text,
@@ -152,8 +221,8 @@
 			} as ChatMessage;
 		});
 		const resList = await Promise.all(
-			(userMsg ?? []).map((item) => {
-				userItemIdMap.set(item.history_id, item);
+			(userMsg ?? []).map((item, index) => {
+				userItemIdMap.set(index, item);
 				return getAnswerById(item.history_id);
 			})
 		);
@@ -162,26 +231,30 @@
 			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 attachList = convertAttach(item?.answer);
+			currentUserMsg.attachList = attachList;
+			const mapUser = userItemIdMap.get(index);
+			const historyId = mapUser?.history_id;
 
 			const answerTime = formatShowTimeYear(mapUser?.create_time);
+
 			tmpMessageList.splice(
 				insertIndex,
 				0,
 				item.answer === null
 					? null
 					: {
-							historyId: item.answer?.history_id,
+							historyId: historyId,
 							role: RoleEnum.assistant,
 							content: parseContent(item?.answer),
 							state: item.answer_state,
 							createTime: answerTime,
 							isStopMsg: false,
-							stepGroup: (item?.answer?.reports ?? []).map((item) => ({
-								value: convertProcessToStep(item?.exec_process),
-								isShow: false,
-							})),
+							// stepGroup: (item?.answer?.reports ?? []).map((item) => ({
+							// 	value: convertProcessToStep(item?.exec_process),
+							// 	isShow: false,
+							// }))
+							stepGroup: getStepGroupList(item?.answer?.reports ?? []),
 
 							conclusion: item?.answer?.conclusion ?? [],
 							isChecked: false,
@@ -205,6 +278,8 @@
 		} as StepItem;
 	};
 	const convertProcessToStep = (process: any[], isHistory = true) => {
+		let streamIsStart = false;
+
 		const stepList = (process ?? []).reduce((preVal, curVal) => {
 			if (curVal.mode === 'question') {
 				if (isHistory) return preVal;
@@ -217,6 +292,15 @@
 					type: MultiChatType.Select,
 				};
 				last.subStep.push(sub);
+			} else if (curVal.mode === 'begin_stream') {
+				streamIsStart = true;
+				const cur = convertProcessItem(curVal);
+				preVal.push(cur);
+			} else if (curVal.mode === 'end_stream') {
+				streamIsStart = false;
+			} else if (streamIsStart) {
+				const last = preVal.at(-1);
+				last.title += curVal.value;
 			} else {
 				const cur = convertProcessItem(curVal);
 				preVal.push(cur);
@@ -232,5 +316,7 @@
 		convertProcessToStep,
 		convertProcessItem,
 		formatShowTimeYear,
+		getStepGroupList,
+		convertAttach,
 	};
 };

--
Gitblit v1.9.3