From 46a5e875efefb071a654bdf14da0e662347a986b Mon Sep 17 00:00:00 2001 From: yangyin <1850366751@qq.com> Date: 星期四, 31 十月 2024 15:23:41 +0800 Subject: [PATCH] 对话时间格式化处理 --- src/components/chat/hooks/useScrollLoad.ts | 29 ++++++++++++++++------------- 1 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/components/chat/hooks/useScrollLoad.ts b/src/components/chat/hooks/useScrollLoad.ts index 27f23bb..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,7 +28,11 @@ history_id: historyId, }); }; - + const formatShowTimeYear = computed(() => { + return (str) => { + return moment(str).format('MM鏈圖D鏃� HH:mm:ss'); + }; + }); /** * 鑾峰彇鐢ㄦ埛鍥炲鏁版嵁锛屽苟鎻掑叆鍒板璇濆綋涓幓 */ @@ -57,7 +61,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, 0, @@ -69,7 +74,7 @@ content: parseAnswerContent(item.answer), state: item.answer_state, sectionAId: mapUser?.section_a_id, - createTime:mapUser?.create_time + createTime: answerTime, } ); i++; @@ -101,7 +106,6 @@ //婊氬姩鐩戝惉 async function onChatListScroll() { if (container.value.scrollTop == 0) { - // 鏇村鏁版嵁姝e湪鍔犺浇鏃� if (moreIsLoading.value) { return; @@ -117,9 +121,9 @@ moreIsLoading.value = false; }); //鏇存柊鍚庯紝绛夊緟椤甸潰娓叉煋瀹屾瘯鍐嶅幓鎷縮crollHeight,鍚﹀垯鎷垮埌鐨勬槸涔嬪墠鐨� - nextTick(()=>{ - nextTick(()=>{ - nextTick(()=>{ + nextTick(() => { + nextTick(() => { + nextTick(() => { let h2 = container.value.scrollHeight; container.value.scrollTo({ //椤堕儴鍦ㄥ師鍏堝熀纭�涓婂線涓嬫粴鍔�50px锛岄湶鍑烘柊鍔犺浇鏁版嵁鐨勪竴鐐� @@ -127,10 +131,9 @@ top: h2 - h1, behavior: 'instant', //auto-鑷姩婊氬姩 instant-鐬棿婊氬姩 smooth-骞虫粦婊氬姩 }); - }) - }) - }) - + }); + }); + }); } } -- Gitblit v1.9.3