perf: scrollToBottom 改成 scrollToBottomIfAtBottom (#771)

This commit is contained in:
舜岳 2023-03-22 18:00:53 +08:00 committed by GitHub
parent b1d0056429
commit 31a84325d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -28,7 +28,7 @@ export function useScroll(): ScrollReturn {
const scrollToBottomIfAtBottom = async () => { const scrollToBottomIfAtBottom = async () => {
await nextTick() await nextTick()
if (scrollRef.value) { if (scrollRef.value) {
const threshold = 50 // 阈值,表示滚动条到底部的距离阈值 const threshold = 100 // 阈值,表示滚动条到底部的距离阈值
const distanceToBottom = scrollRef.value.scrollHeight - scrollRef.value.scrollTop - scrollRef.value.clientHeight const distanceToBottom = scrollRef.value.scrollHeight - scrollRef.value.scrollTop - scrollRef.value.clientHeight
if (distanceToBottom <= threshold) if (distanceToBottom <= threshold)
scrollRef.value.scrollTop = scrollRef.value.scrollHeight scrollRef.value.scrollTop = scrollRef.value.scrollHeight

View File

@ -30,7 +30,7 @@ useCopyCode()
const { isMobile } = useBasicLayout() const { isMobile } = useBasicLayout()
const { addChat, updateChat, updateChatSome, getChatByUuidAndIndex } = useChat() const { addChat, updateChat, updateChatSome, getChatByUuidAndIndex } = useChat()
const { scrollRef, scrollToBottom } = useScroll() const { scrollRef, scrollToBottom, scrollToBottomIfAtBottom } = useScroll()
const { usingContext, toggleUsingContext } = useUsingContext() const { usingContext, toggleUsingContext } = useUsingContext()
const { uuid } = route.params as { uuid: string } const { uuid } = route.params as { uuid: string }
@ -142,7 +142,7 @@ async function onConversation() {
return fetchChatAPIOnce() return fetchChatAPIOnce()
} }
scrollToBottom() scrollToBottomIfAtBottom()
} }
catch (error) { catch (error) {
// //
@ -164,7 +164,7 @@ async function onConversation() {
loading: false, loading: false,
}, },
) )
scrollToBottom() scrollToBottomIfAtBottom()
return return
} }
@ -196,7 +196,7 @@ async function onConversation() {
requestOptions: { prompt: message, options: { ...options } }, requestOptions: { prompt: message, options: { ...options } },
}, },
) )
scrollToBottom() scrollToBottomIfAtBottom()
} }
finally { finally {
loading.value = false loading.value = false