From 1b2f0b514d7ef9bc7850b643647060f88818e898 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=88=9C=E5=B2=B3?= <1277952981@qq.com> Date: Wed, 22 Mar 2023 18:00:53 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20scrollToBottom=20=E6=94=B9=E6=88=90=20s?= =?UTF-8?q?crollToBottomIfAtBottom=20(#771)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/chat/hooks/useScroll.ts | 2 +- src/views/chat/index.vue | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/views/chat/hooks/useScroll.ts b/src/views/chat/hooks/useScroll.ts index e5e4b35574..16987adbe1 100644 --- a/src/views/chat/hooks/useScroll.ts +++ b/src/views/chat/hooks/useScroll.ts @@ -28,7 +28,7 @@ export function useScroll(): ScrollReturn { const scrollToBottomIfAtBottom = async () => { await nextTick() if (scrollRef.value) { - const threshold = 50 // 阈值,表示滚动条到底部的距离阈值 + const threshold = 100 // 阈值,表示滚动条到底部的距离阈值 const distanceToBottom = scrollRef.value.scrollHeight - scrollRef.value.scrollTop - scrollRef.value.clientHeight if (distanceToBottom <= threshold) scrollRef.value.scrollTop = scrollRef.value.scrollHeight diff --git a/src/views/chat/index.vue b/src/views/chat/index.vue index 82f3235a4a..9ed9fdd8a7 100644 --- a/src/views/chat/index.vue +++ b/src/views/chat/index.vue @@ -30,7 +30,7 @@ useCopyCode() const { isMobile } = useBasicLayout() const { addChat, updateChat, updateChatSome, getChatByUuidAndIndex } = useChat() -const { scrollRef, scrollToBottom } = useScroll() +const { scrollRef, scrollToBottom, scrollToBottomIfAtBottom } = useScroll() const { usingContext, toggleUsingContext } = useUsingContext() const { uuid } = route.params as { uuid: string } @@ -142,7 +142,7 @@ async function onConversation() { return fetchChatAPIOnce() } - scrollToBottom() + scrollToBottomIfAtBottom() } catch (error) { // @@ -164,7 +164,7 @@ async function onConversation() { loading: false, }, ) - scrollToBottom() + scrollToBottomIfAtBottom() return } @@ -196,7 +196,7 @@ async function onConversation() { requestOptions: { prompt: message, options: { ...options } }, }, ) - scrollToBottom() + scrollToBottomIfAtBottom() } finally { loading.value = false