Skip to content

Commit 5b9daba

Browse files
author
Kerwin
committed
fix: 无法滚动倒底部 (Close #74)
1 parent 65d6f33 commit 5b9daba

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

src/views/chat/index.vue

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang='ts'>
22
import type { Ref } from 'vue'
3-
import { computed, defineAsyncComponent, nextTick, onMounted, onUnmounted, ref } from 'vue'
3+
import { computed, defineAsyncComponent, nextTick, onMounted, onUnmounted, ref, watch } from 'vue'
44
import { useRoute } from 'vue-router'
55
import { storeToRefs } from 'pinia'
66
import type { MessageReactive } from 'naive-ui'
@@ -471,6 +471,16 @@ async function loadMoreMessage(event: any) {
471471
}
472472
473473
const handleLoadMoreMessage = debounce(loadMoreMessage, 300)
474+
const handleSyncChat
475+
= debounce(() => {
476+
// 直接刷 极小概率不请求
477+
chatStore.syncChat({ uuid: Number(uuid) } as Chat.History, undefined, () => {
478+
firstLoading.value = false
479+
scrollToBottom()
480+
if (inputRef.value && !isMobile.value)
481+
inputRef.value?.focus()
482+
})
483+
}, 200)
474484
475485
async function handleScroll(event: any) {
476486
const scrollTop = event.target.scrollTop
@@ -524,15 +534,11 @@ const footerClass = computed(() => {
524534
525535
onMounted(() => {
526536
firstLoading.value = true
527-
debounce(() => {
528-
// 直接刷 极小概率不请求
529-
chatStore.syncChat({ uuid: Number(uuid) } as Chat.History, undefined, () => {
530-
firstLoading.value = false
531-
scrollToBottom()
532-
if (inputRef.value && !isMobile.value)
533-
inputRef.value?.focus()
534-
})
535-
}, 200)()
537+
handleSyncChat()
538+
})
539+
540+
watch(() => chatStore.active, (newVal, oldVal) => {
541+
handleSyncChat()
536542
})
537543
538544
onUnmounted(() => {

src/views/chat/layout/sider/List.vue

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
<script setup lang='ts'>
22
import { computed, onMounted, ref } from 'vue'
33
import { NInput, NPopconfirm, NScrollbar, NSpin } from 'naive-ui'
4-
import { useScroll } from '../../hooks/useScroll'
54
import { SvgIcon } from '@/components/common'
65
import { useAppStore, useChatStore } from '@/store'
76
import { useBasicLayout } from '@/hooks/useBasicLayout'
87
import { useAuthStoreWithout } from '@/store/modules/auth'
98
import { debounce } from '@/utils/functions/debounce'
109
11-
const { scrollToBottom } = useScroll()
12-
1310
const { isMobile } = useBasicLayout()
1411
1512
const appStore = useAppStore()
@@ -26,15 +23,9 @@ onMounted(async () => {
2623
})
2724
2825
async function handleSyncChatRoom() {
29-
// if (chatStore.history.length == 1 && chatStore.history[0].title == 'New Chat'
30-
// && chatStore.chat[0].data.length <= 0)
3126
loadingRoom.value = true
3227
chatStore.syncHistory(() => {
3328
loadingRoom.value = false
34-
if (chatStore.active) {
35-
const uuid = chatStore.active
36-
chatStore.syncChat({ uuid } as Chat.History, undefined, scrollToBottom)
37-
}
3829
})
3930
}
4031

0 commit comments

Comments
 (0)