From 5e8b3e27c4a847be602e97bcd586ab6627108484 Mon Sep 17 00:00:00 2001
From: yangyin <1850366751@qq.com>
Date: 星期一, 04 十一月 2024 11:16:35 +0800
Subject: [PATCH] 光标快速输入键盘上下箭头设置为快捷语

---
 src/components/chat/hooks/useScrollLoad.ts |   37 ++++++++++++++++++++++---------------
 1 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/src/components/chat/hooks/useScrollLoad.ts b/src/components/chat/hooks/useScrollLoad.ts
index 1366c96..2f74288 100644
--- a/src/components/chat/hooks/useScrollLoad.ts
+++ b/src/components/chat/hooks/useScrollLoad.ts
@@ -1,8 +1,8 @@
-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';
-
 type UseScrollLoadOption = {
 	container: ShallowRef<HTMLDivElement>;
 	historyGroupId: string | Ref<string>;
@@ -28,12 +28,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,
@@ -46,7 +51,7 @@
 		});
 		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 +60,9 @@
 			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 +73,8 @@
 							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,
 					  }
 			);
 			i++;
@@ -79,7 +88,7 @@
 	 */
 	const loadRangeData = async (lastEnd = nextUserMsgEndIndex.value) => {
 		const res = await QueryHistoryDetail({
-			history_group_id: unref(historyGroupId),,
+			history_group_id: unref(historyGroupId),
 			last_end: lastEnd,
 			last_count: LOAD_CHAT_LIMIT,
 		});
@@ -97,7 +106,6 @@
 	//婊氬姩鐩戝惉
 	async function onChatListScroll() {
 		if (container.value.scrollTop == 0) {
-
 			// 鏇村鏁版嵁姝e湪鍔犺浇鏃�
 			if (moreIsLoading.value) {
 				return;
@@ -113,9 +121,9 @@
 				moreIsLoading.value = false;
 			});
 			//鏇存柊鍚庯紝绛夊緟椤甸潰娓叉煋瀹屾瘯鍐嶅幓鎷縮crollHeight,鍚﹀垯鎷垮埌鐨勬槸涔嬪墠鐨�
-			nextTick(()=>{
-				nextTick(()=>{
-					nextTick(()=>{
+			nextTick(() => {
+				nextTick(() => {
+					nextTick(() => {
 						let h2 = container.value.scrollHeight;
 						container.value.scrollTo({
 							//椤堕儴鍦ㄥ師鍏堝熀纭�涓婂線涓嬫粴鍔�50px锛岄湶鍑烘柊鍔犺浇鏁版嵁鐨勪竴鐐�
@@ -123,10 +131,9 @@
 							top: h2 - h1,
 							behavior: 'instant', //auto-鑷姩婊氬姩 instant-鐬棿婊氬姩 smooth-骞虫粦婊氬姩
 						});
-					})
-				})
-			})
-
+					});
+				});
+			});
 		}
 	}
 

--
Gitblit v1.9.3