From 9098e6b4f73291a437b61d820d4ff4064741c2dd Mon Sep 17 00:00:00 2001 From: hubian <908234780@qq.com> Date: Sun, 26 Apr 2026 22:48:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20AI=E7=94=9F=E6=88=90=E6=97=B6=E6=99=BA?= =?UTF-8?q?=E8=83=BD=E6=BB=9A=E5=8A=A8=20-=20=E7=94=A8=E6=88=B7=E5=8F=AF?= =?UTF-8?q?=E8=87=AA=E7=94=B1=E6=BB=9A=E5=8A=A8=E6=9F=A5=E7=9C=8B=EF=BC=8C?= =?UTF-8?q?=E5=8F=AA=E5=9C=A8=E5=BA=95=E9=83=A8=E6=97=B6=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=BB=9A=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- www/app.js | 36 ++++++++++++++++++++++++++++++++++-- www/index.html | 6 +++--- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/www/app.js b/www/app.js index c31c5b5..512a8d5 100644 --- a/www/app.js +++ b/www/app.js @@ -19,6 +19,7 @@ let isLoading = false; // 功能开关 let enableThinking = false; // 深度思考 let enableSearch = false; // 联网搜索 +let autoScrollEnabled = true; // 自动滚动(用户滚动后可关闭) // DOM 元素(初始为 null,在 openConversation 时重新获取) let appContainer = null; @@ -575,6 +576,12 @@ function openConversation(id) { thinkingBtn = document.getElementById('thinkingBtn'); searchBtn = document.getElementById('searchBtn'); + // 重置自动滚动状态 + autoScrollEnabled = true; + + // 设置滚动监听 + setupScrollListener(); + // 绑定按钮事件 const backBtn = document.getElementById('backBtn'); if (backBtn) backBtn.addEventListener('click', showConversationList); @@ -739,6 +746,9 @@ async function sendMessage() { currentConversation.updatedAt = Date.now(); saveConversations(); + // 发送新消息时启用自动滚动 + autoScrollEnabled = true; + renderMessages(); userInput.value = ''; autoResize(userInput); @@ -1298,10 +1308,32 @@ function renderMarkdown(text) { return marked.parse(text); } -// 滚动到底部 +// 滚动到底部(智能滚动:只在用户已在底部时自动滚动) function scrollToBottom() { if (messagesContainer) { - messagesContainer.scrollTop = messagesContainer.scrollHeight; + // 判断用户是否在底部附近(距离底部100px以内) + const isNearBottom = messagesContainer.scrollHeight - messagesContainer.scrollTop - messagesContainer.clientHeight < 100; + + if (isNearBottom || autoScrollEnabled) { + messagesContainer.scrollTop = messagesContainer.scrollHeight; + } + } +} + +// 监听用户滚动行为 +function setupScrollListener() { + if (messagesContainer) { + messagesContainer.addEventListener('scroll', () => { + // 判断用户是否在底部附近 + const isNearBottom = messagesContainer.scrollHeight - messagesContainer.scrollTop - messagesContainer.clientHeight < 100; + + if (isNearBottom) { + autoScrollEnabled = true; + } else { + // 用户往上滚动,停止自动滚动 + autoScrollEnabled = false; + } + }); } } diff --git a/www/index.html b/www/index.html index c3a395e..d0cde40 100644 --- a/www/index.html +++ b/www/index.html @@ -8,12 +8,12 @@