diff --git a/src/views/chat/components/Message/Text.vue b/src/views/chat/components/Message/Text.vue index 61736a1..cca4d1a 100644 --- a/src/views/chat/components/Message/Text.vue +++ b/src/views/chat/components/Message/Text.vue @@ -38,7 +38,7 @@ const wrapClass = computed(() => { 'text-wrap', 'min-w-[20px]', 'rounded-md', - isMobile.value ? 'p-2' : 'p-3', + isMobile.value ? 'p-2' : 'px-3 py-2', props.inversion ? 'bg-[#d2f9d1]' : 'bg-[#f4f6f8]', props.inversion ? 'dark:bg-[#a1dc95]' : 'dark:bg-[#1e1e20]', { 'text-red-500': props.error }, diff --git a/src/views/chat/hooks/useScroll.ts b/src/views/chat/hooks/useScroll.ts index 9edddbf..e5e4b35 100644 --- a/src/views/chat/hooks/useScroll.ts +++ b/src/views/chat/hooks/useScroll.ts @@ -7,7 +7,7 @@ interface ScrollReturn { scrollRef: Ref scrollToBottom: () => Promise scrollToTop: () => Promise - scrollToBottomIfAtBottom: () => Promise + scrollToBottomIfAtBottom: () => Promise } export function useScroll(): ScrollReturn { @@ -26,20 +26,19 @@ export function useScroll(): ScrollReturn { } const scrollToBottomIfAtBottom = async () => { - await nextTick() + await nextTick() if (scrollRef.value) { const threshold = 50 // 阈值,表示滚动条到底部的距离阈值 const distanceToBottom = scrollRef.value.scrollHeight - scrollRef.value.scrollTop - scrollRef.value.clientHeight - if (distanceToBottom <= threshold) { + if (distanceToBottom <= threshold) scrollRef.value.scrollTop = scrollRef.value.scrollHeight - } } } - + return { scrollRef, scrollToBottom, scrollToTop, - scrollToBottomIfAtBottom, + scrollToBottomIfAtBottom, } } diff --git a/src/views/chat/index.vue b/src/views/chat/index.vue index b837a2f..7ac5275 100644 --- a/src/views/chat/index.vue +++ b/src/views/chat/index.vue @@ -120,7 +120,6 @@ async function onConversation() { } }, }) - scrollToBottomIfAtBottom() } catch (error: any) { const errorMessage = error?.message ?? t('common.wrong') @@ -165,10 +164,10 @@ async function onConversation() { requestOptions: { prompt: message, options: { ...options } }, }, ) - scrollToBottom() } finally { loading.value = false + scrollToBottom() } } @@ -406,7 +405,11 @@ onUnmounted(() => { ref="scrollRef" class="h-full overflow-hidden overflow-y-auto" > -
+