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" />