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 pzcn committed Mar 22, 2023
1 parent ab9e4b7 commit 8eb9e50
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 @@ -147,7 +147,7 @@ async function onConversation() {
return fetchChatAPIOnce()
}
scrollToBottom()
scrollToBottomIfAtBottom()
}
catch (error) {
//
Expand All @@ -169,7 +169,7 @@ async function onConversation() {
loading: false,
},
)
scrollToBottom()
scrollToBottomIfAtBottom()
return
}
Expand Down Expand Up @@ -201,7 +201,7 @@ async function onConversation() {
requestOptions: { prompt: message, options: { ...options } },
},
)
scrollToBottom()
scrollToBottomIfAtBottom()
}
finally {
loading.value = false
Expand Down

0 comments on commit 8eb9e50

Please sign in to comment.