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