From d70549c9b1e318d609322c17812c20b7d114b28d Mon Sep 17 00:00:00 2001 From: digua Date: Tue, 2 Dec 2025 00:07:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E8=81=8A=E5=A4=A9=E8=AE=B0=E5=BD=95=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/main/database/core.ts | 24 ++++ electron/main/ipcMain.ts | 15 +++ electron/preload/index.d.ts | 1 + electron/preload/index.ts | 7 ++ src/components/common/Sidebar.vue | 186 ++++++++++++++++++------------ src/pages/tools.vue | 2 +- src/stores/chat.ts | 21 ++++ 7 files changed, 180 insertions(+), 76 deletions(-) diff --git a/electron/main/database/core.ts b/electron/main/database/core.ts index 8a7668e..96a0e41 100644 --- a/electron/main/database/core.ts +++ b/electron/main/database/core.ts @@ -371,6 +371,30 @@ export function deleteSession(sessionId: string): boolean { } } +/** + * 重命名会话 + */ +export function renameSession(sessionId: string, newName: string): boolean { + const dbPath = getDbPath(sessionId) + if (!fs.existsSync(dbPath)) { + return false + } + + try { + const db = new Database(dbPath) + db.pragma('journal_mode = WAL') + + const stmt = db.prepare('UPDATE meta SET name = ?') + stmt.run(newName) + + db.close() + return true + } catch (error) { + console.error('[Database] Failed to rename session:', error) + return false + } +} + /** * 获取数据库存储目录 */ diff --git a/electron/main/ipcMain.ts b/electron/main/ipcMain.ts index 6a5fe59..c7a67e8 100644 --- a/electron/main/ipcMain.ts +++ b/electron/main/ipcMain.ts @@ -260,6 +260,21 @@ const mainIpcMain = (win: BrowserWindow) => { } }) + /** + * 重命名会话 + */ + ipcMain.handle('chat:renameSession', async (_, sessionId: string, newName: string) => { + try { + // 先关闭 Worker 中的数据库连接(确保没有其他进程占用) + await worker.closeDatabase(sessionId) + // 执行重命名 + return databaseCore.renameSession(sessionId, newName) + } catch (error) { + console.error('重命名会话失败:', error) + return false + } + }) + /** * 获取可用年份列表 */ diff --git a/electron/preload/index.d.ts b/electron/preload/index.d.ts index 38bb4ab..ce48e2c 100644 --- a/electron/preload/index.d.ts +++ b/electron/preload/index.d.ts @@ -36,6 +36,7 @@ interface ChatApi { getSessions: () => Promise getSession: (sessionId: string) => Promise deleteSession: (sessionId: string) => Promise + renameSession: (sessionId: string, newName: string) => Promise getAvailableYears: (sessionId: string) => Promise getMemberActivity: (sessionId: string, filter?: TimeFilter) => Promise getMemberNameHistory: (sessionId: string, memberId: number) => Promise diff --git a/electron/preload/index.ts b/electron/preload/index.ts index b765cd4..83d4867 100644 --- a/electron/preload/index.ts +++ b/electron/preload/index.ts @@ -90,6 +90,13 @@ const chatApi = { return ipcRenderer.invoke('chat:deleteSession', sessionId) }, + /** + * 重命名会话 + */ + renameSession: (sessionId: string, newName: string): Promise => { + return ipcRenderer.invoke('chat:renameSession', sessionId, newName) + }, + /** * 获取可用年份列表 */ diff --git a/src/components/common/Sidebar.vue b/src/components/common/Sidebar.vue index ab4f852..0597abf 100644 --- a/src/components/common/Sidebar.vue +++ b/src/components/common/Sidebar.vue @@ -1,8 +1,9 @@ @@ -86,7 +132,7 @@ function cancelDelete() { - + - - 工具广场 + + 实用工具 @@ -111,8 +157,9 @@ function cancelDelete() {
暂无记录
-
- 聊天记录 +
+
聊天记录
+
右键删除或重命名
-
- +
- {{ session.name ? session.name.charAt(0) : '?' }} -
+ +
+ {{ session.name ? session.name.charAt(0) : '?' }} +
- -
-

- {{ session.name }} -

-

- {{ session.messageCount }} 条消息 · {{ formatTime(session.importedAt) }} -

+ +
+

+ {{ session.name }} +

+

+ {{ session.messageCount }} 条消息 · {{ formatTime(session.importedAt) }} +

+
- - -
- - - - - -
-
+
+ + + + +
diff --git a/src/pages/tools.vue b/src/pages/tools.vue index 074f2ad..625287c 100644 --- a/src/pages/tools.vue +++ b/src/pages/tools.vue @@ -12,7 +12,7 @@ const activeTab = ref('merge')
-

工具广场

+

实用工具

提供聊天记录处理的实用工具

diff --git a/src/stores/chat.ts b/src/stores/chat.ts index 1042cdd..deaa088 100644 --- a/src/stores/chat.ts +++ b/src/stores/chat.ts @@ -190,6 +190,26 @@ export const useChatStore = defineStore( } } + /** + * 重命名会话 + */ + async function renameSession(id: string, newName: string): Promise { + try { + const success = await window.chatApi.renameSession(id, newName) + if (success) { + // 更新本地列表中的名称 + const session = sessions.value.find((s) => s.id === id) + if (session) { + session.name = newName + } + } + return success + } catch (error) { + console.error('重命名会话失败:', error) + return false + } + } + /** * 清除选中状态 */ @@ -245,6 +265,7 @@ export const useChatStore = defineStore( importFileFromPath, selectSession, deleteSession, + renameSession, clearSelection, toggleSidebar, addCustomKeywordTemplate,