Skip to content

Commit

Permalink
fix: 无法滚动倒底部 (Close #74)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerwin committed Apr 26, 2023
1 parent 65d6f33 commit 5b9daba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
26 changes: 16 additions & 10 deletions src/views/chat/index.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang='ts'>
import type { Ref } from 'vue'
import { computed, defineAsyncComponent, nextTick, onMounted, onUnmounted, ref } from 'vue'
import { computed, defineAsyncComponent, nextTick, onMounted, onUnmounted, ref, watch } from 'vue'
import { useRoute } from 'vue-router'
import { storeToRefs } from 'pinia'
import type { MessageReactive } from 'naive-ui'
Expand Down Expand Up @@ -471,6 +471,16 @@ async function loadMoreMessage(event: any) {
}
const handleLoadMoreMessage = debounce(loadMoreMessage, 300)
const handleSyncChat
= debounce(() => {
// 直接刷 极小概率不请求
chatStore.syncChat({ uuid: Number(uuid) } as Chat.History, undefined, () => {
firstLoading.value = false
scrollToBottom()
if (inputRef.value && !isMobile.value)
inputRef.value?.focus()
})
}, 200)
async function handleScroll(event: any) {
const scrollTop = event.target.scrollTop
Expand Down Expand Up @@ -524,15 +534,11 @@ const footerClass = computed(() => {
onMounted(() => {
firstLoading.value = true
debounce(() => {
// 直接刷 极小概率不请求
chatStore.syncChat({ uuid: Number(uuid) } as Chat.History, undefined, () => {
firstLoading.value = false
scrollToBottom()
if (inputRef.value && !isMobile.value)
inputRef.value?.focus()
})
}, 200)()
handleSyncChat()
})
watch(() => chatStore.active, (newVal, oldVal) => {
handleSyncChat()
})
onUnmounted(() => {
Expand Down
9 changes: 0 additions & 9 deletions src/views/chat/layout/sider/List.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
<script setup lang='ts'>
import { computed, onMounted, ref } from 'vue'
import { NInput, NPopconfirm, NScrollbar, NSpin } from 'naive-ui'
import { useScroll } from '../../hooks/useScroll'
import { SvgIcon } from '@/components/common'
import { useAppStore, useChatStore } from '@/store'
import { useBasicLayout } from '@/hooks/useBasicLayout'
import { useAuthStoreWithout } from '@/store/modules/auth'
import { debounce } from '@/utils/functions/debounce'
const { scrollToBottom } = useScroll()
const { isMobile } = useBasicLayout()
const appStore = useAppStore()
Expand All @@ -26,15 +23,9 @@ onMounted(async () => {
})
async function handleSyncChatRoom() {
// if (chatStore.history.length == 1 && chatStore.history[0].title == 'New Chat'
// && chatStore.chat[0].data.length <= 0)
loadingRoom.value = true
chatStore.syncHistory(() => {
loadingRoom.value = false
if (chatStore.active) {
const uuid = chatStore.active
chatStore.syncChat({ uuid } as Chat.History, undefined, scrollToBottom)
}
})
}
Expand Down

0 comments on commit 5b9daba

Please sign in to comment.