From 0812a6192ff1977a2632d7cda45d0b5ee8edb980 Mon Sep 17 00:00:00 2001 From: hubian <908234780@qq.com> Date: Mon, 27 Apr 2026 11:18:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=99=AE=E9=80=9A=E5=AF=B9=E8=AF=9D?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=90=8E=E4=B8=8D=E5=86=8D=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E6=99=BA=E8=83=BD=E4=BD=93=E5=AF=B9=E8=AF=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - showConversationList 简化为直接返回主页 - 主页对话列表正确过滤(只显示没有 agentId 的普通对话) - 添加操作菜单支持(重命名、分享、置顶、删除) - 统一使用全局变量 currentActionConvId --- www/app.js | 279 +++++++++---------------------------------------- www/index.html | 6 +- 2 files changed, 50 insertions(+), 235 deletions(-) diff --git a/www/app.js b/www/app.js index e1fe6f7..f3bcf95 100644 --- a/www/app.js +++ b/www/app.js @@ -494,6 +494,28 @@ function renderChatsPage() { + +
+
+
+ + 重命名 +
+
+ + 分享 +
+
+ + 置顶 +
+
+ + 删除 +
+
+
+ @@ -1983,9 +2025,11 @@ function showAgentChatPage() { } // 设置长按事件 +// 全局变量:当前操作的对话ID +let currentActionConvId = null; + function setupLongPressEvents(container) { let longPressTimer = null; - let currentActionConvId = null; container.addEventListener('touchstart', (e) => { const item = e.target.closest('.conversation-item'); @@ -2038,236 +2082,7 @@ function setupLongPressEvents(container) { function showConversationList() { currentConversation = null; - - // 渲染对话列表 - const listHtml = ` -
-
-
- -

AI助手

-
-
- - -
-
- -
-
- ${conversations.length === 0 - ? '
暂无对话记录
' - : sortConversations().map(conv => ` -
- ${conv.is_pinned ? '📌' : ''} -
${escapeHtml(conv.title)}
-
${conv.messages.length} 条消息 · ${formatTime(conv.updatedAt)}
-
- `).join('') - } -
-
- - -
-
-
- - 重命名 -
-
- - 分享 -
-
- - 置顶 -
-
- - 删除 -
-
-
- - - - -
- - `; - - appContainer.innerHTML = listHtml; - - // 绑定事件 - const newChatBtn = document.getElementById('newChatBtn'); - if (newChatBtn) { - newChatBtn.addEventListener('click', createNewConversation); - } - - // 搜索功能 - const searchToggleBtn = document.getElementById('searchToggleBtn'); - const searchBar = document.getElementById('searchBar'); - const searchInput = document.getElementById('searchInput'); - const searchCloseBtn = document.getElementById('searchCloseBtn'); - const searchResults = document.getElementById('searchResults'); - - if (searchToggleBtn) { - searchToggleBtn.addEventListener('click', () => { - if (searchBar) { - searchBar.classList.add('show'); - if (searchInput) { - searchInput.focus(); - } - } - }); - } - - if (searchCloseBtn) { - searchCloseBtn.addEventListener('click', () => { - hideSearchBar(); - }); - } - - if (searchInput) { - searchInput.addEventListener('input', (e) => { - const keyword = e.target.value.trim(); - if (keyword) { - searchConversations(keyword); - } else { - if (searchResults) searchResults.innerHTML = ''; - } - }); - - searchInput.addEventListener('keydown', (e) => { - if (e.key === 'Escape') { - hideSearchBar(); - } - }); - } - - // 点击搜索结果 - if (searchResults) { - searchResults.addEventListener('click', (e) => { - const item = e.target.closest('.search-result-item'); - if (item) { - const id = item.getAttribute('data-id'); - hideSearchBar(); - openConversation(id); - } - }); - } - - function hideSearchBar() { - if (searchBar) { - searchBar.classList.remove('show'); - } - if (searchInput) { - searchInput.value = ''; - } - if (searchResults) { - searchResults.innerHTML = ''; - } - } - - const conversationList = document.getElementById('conversationList'); - const actionMenu = document.getElementById('actionMenu'); - let longPressTimer = null; - let currentActionConvId = null; - - if (conversationList) { - // 点击事件 - conversationList.addEventListener('click', (e) => { - const item = e.target.closest('.conversation-item'); - - if (item) { - const id = item.getAttribute('data-id'); - openConversation(id); - } - }); - - // 长按事件 - conversationList.addEventListener('touchstart', (e) => { - const item = e.target.closest('.conversation-item'); - if (item) { - longPressTimer = setTimeout(() => { - currentActionConvId = item.getAttribute('data-id'); - showActionMenu(currentActionConvId); - }, 500); // 500ms长按 - } - }); - - conversationList.addEventListener('touchend', () => { - if (longPressTimer) { - clearTimeout(longPressTimer); - longPressTimer = null; - } - }); - - conversationList.addEventListener('touchmove', () => { - if (longPressTimer) { - clearTimeout(longPressTimer); - longPressTimer = null; - } - }); - - // 鼠标长按(PC端) - conversationList.addEventListener('mousedown', (e) => { - const item = e.target.closest('.conversation-item'); - if (item) { - longPressTimer = setTimeout(() => { - currentActionConvId = item.getAttribute('data-id'); - showActionMenu(currentActionConvId); - }, 500); - } - }); - - conversationList.addEventListener('mouseup', () => { - if (longPressTimer) { - clearTimeout(longPressTimer); - longPressTimer = null; - } - }); - - conversationList.addEventListener('mouseleave', () => { - if (longPressTimer) { - clearTimeout(longPressTimer); - longPressTimer = null; - } - }); - } - - // 操作菜单事件 - if (actionMenu) { - actionMenu.addEventListener('click', (e) => { - const item = e.target.closest('.action-menu-item'); - if (item && currentActionConvId) { - const action = item.getAttribute('data-action'); - handleActionMenuAction(action, currentActionConvId); - hideActionMenu(); - } - }); - - // 点击其他地方关闭菜单 - document.addEventListener('click', (e) => { - if (actionMenu.classList.contains('show') && !actionMenu.contains(e.target)) { - hideActionMenu(); - } - }); - } + showMainPage(); // 返回主页,会正确显示过滤后的对话列表 } // 排序对话(置顶在前) diff --git a/www/index.html b/www/index.html index 7d5b759..6a26fb3 100644 --- a/www/index.html +++ b/www/index.html @@ -8,12 +8,12 @@ AI助手 - +
- - + + \ No newline at end of file