|
1 | 1 | <script setup lang='ts'> |
2 | 2 | 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' |
4 | 4 | import { useRoute } from 'vue-router' |
5 | 5 | import { storeToRefs } from 'pinia' |
6 | 6 | import type { MessageReactive } from 'naive-ui' |
@@ -471,6 +471,16 @@ async function loadMoreMessage(event: any) { |
471 | 471 | } |
472 | 472 |
|
473 | 473 | 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) |
474 | 484 |
|
475 | 485 | async function handleScroll(event: any) { |
476 | 486 | const scrollTop = event.target.scrollTop |
@@ -524,15 +534,11 @@ const footerClass = computed(() => { |
524 | 534 |
|
525 | 535 | onMounted(() => { |
526 | 536 | 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() |
536 | 542 | }) |
537 | 543 |
|
538 | 544 | onUnmounted(() => { |
|
0 commit comments