Skip to content

Commit

Permalink
perf: scrollToBottom 改成 scrollToBottomIfAtBottom (Chanzhaoyu#771)
Browse files Browse the repository at this point in the history
  • Loading branch information
shunyue1320 authored and jingChen55 committed Mar 27, 2023
1 parent 659617c commit 1b2f0b5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/views/chat/hooks/useScroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/views/chat/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -142,7 +142,7 @@ async function onConversation() {
return fetchChatAPIOnce()
}
scrollToBottom()
scrollToBottomIfAtBottom()
}
catch (error) {
//
Expand All @@ -164,7 +164,7 @@ async function onConversation() {
loading: false,
},
)
scrollToBottom()
scrollToBottomIfAtBottom()
return
}
Expand Down Expand Up @@ -196,7 +196,7 @@ async function onConversation() {
requestOptions: { prompt: message, options: { ...options } },
},
)
scrollToBottom()
scrollToBottomIfAtBottom()
}
finally {
loading.value = false
Expand Down

0 comments on commit 1b2f0b5

Please sign in to comment.