From 43ee2b49031e98d78d2cffd49a95d21347e8d0de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E6=9D=B0?= Date: Mon, 18 Aug 2025 14:07:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E6=83=85=E7=BB=AA=E5=A4=A7?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E5=86=85=E9=83=A8=E6=BB=9A=E5=8A=A8=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E4=BB=A5=E8=A7=A3=E5=86=B3=E7=A7=BB=E5=8A=A8=E7=AB=AF?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E8=82=A1=E7=A5=A8=E5=90=8E=E5=8D=8A=E6=BB=9A?= =?UTF-8?q?=E5=8A=A8=E9=97=AE=E9=A2=98=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/AiEmotion.vue | 26 ++++---------------------- src/views/homePage.vue | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/views/AiEmotion.vue b/src/views/AiEmotion.vue index 6e05368..9a6670f 100644 --- a/src/views/AiEmotion.vue +++ b/src/views/AiEmotion.vue @@ -2982,30 +2982,12 @@ const scrollToTop = () => { const heightObserver = ref(null); const isAutoScrollEnabled = ref(false); -// 滚动到底部功能 +// 滚动到底部功能 - 通过emit通知父组件进行容器滚动 const scrollToBottom = () => { // 使用nextTick确保DOM已更新 nextTick(() => { - // 获取页面的总高度 - const documentHeight = Math.max( - document.body.scrollHeight, - document.body.offsetHeight, - document.documentElement.clientHeight, - document.documentElement.scrollHeight, - document.documentElement.offsetHeight - ); - - // 平滑滚动到页面底部 - window.scrollTo({ - top: documentHeight, - behavior: "smooth", - }); - - // 备用方案:直接设置滚动位置 - setTimeout(() => { - document.documentElement.scrollTop = documentHeight; - document.body.scrollTop = documentHeight; - }, 1000); + // 通过emit事件通知父组件进行滚动 + emit('scrollToBottom'); }); }; @@ -3327,7 +3309,7 @@ onUnmounted(() => { }); // 声明组件可以触发的事件 -const emit = defineEmits(["updateMessage", "sendMessage", "ensureAIchat", "enableInput"]); +const emit = defineEmits(["updateMessage", "sendMessage", "ensureAIchat", "enableInput", "scrollToBottom"]); // 导出方法供外部使用(已在上方定义) diff --git a/src/views/homePage.vue b/src/views/homePage.vue index e6df4e3..754cd64 100644 --- a/src/views/homePage.vue +++ b/src/views/homePage.vue @@ -500,6 +500,20 @@ const handleAiEmotionUserScroll = () => { }, 2000); }; +// 处理AiEmotion页面的滚动请求 +const handleAiEmotionScrollToBottom = () => { + if (activeTab.value === 'AiEmotion') { + const container = tabContentAiEmotion.value; + if (container) { + // 使用nextTick确保DOM已更新 + nextTick(() => { + container.scrollTop = container.scrollHeight - container.offsetHeight; + console.log("AiEmotion页面:执行容器滚动到底部"); + }); + } + } +}; + // 停止AiEmotion页面高度监听器 const stopAiEmotionHeightObserver = () => { isAiEmotionAutoScrollEnabled.value = false; @@ -1056,6 +1070,7 @@ onUnmounted(() => { @sendMessage="sendMessage" @ensureAIchat="ensureAIchat" @enableInput="enableInput" + @scrollToBottom="handleAiEmotionScrollToBottom" ref="aiEmotionRef" />