diff --git a/astrbot/dashboard/routes/conversation.py b/astrbot/dashboard/routes/conversation.py index fb5d3e10e..56f892f24 100644 --- a/astrbot/dashboard/routes/conversation.py +++ b/astrbot/dashboard/routes/conversation.py @@ -169,15 +169,65 @@ class ConversationRoute(Route): """删除对话""" try: data = await request.get_json() - user_id = data.get("user_id") - cid = data.get("cid") - if not user_id or not cid: - return Response().error("缺少必要参数: user_id 和 cid").__dict__ - await self.core_lifecycle.conversation_manager.delete_conversation( - unified_msg_origin=user_id, conversation_id=cid - ) - return Response().ok({"message": "对话删除成功"}).__dict__ + # 检查是否是批量删除 + if "conversations" in data: + # 批量删除 + conversations = data.get("conversations", []) + if not conversations: + return ( + Response().error("批量删除时conversations参数不能为空").__dict__ + ) + + deleted_count = 0 + failed_items = [] + + for conv in conversations: + user_id = conv.get("user_id") + cid = conv.get("cid") + + if not user_id or not cid: + failed_items.append( + f"user_id:{user_id}, cid:{cid} - 缺少必要参数" + ) + continue + + try: + await self.core_lifecycle.conversation_manager.delete_conversation( + unified_msg_origin=user_id, conversation_id=cid + ) + deleted_count += 1 + except Exception as e: + failed_items.append(f"user_id:{user_id}, cid:{cid} - {str(e)}") + + message = f"成功删除 {deleted_count} 个对话" + if failed_items: + message += f",失败 {len(failed_items)} 个" + + return ( + Response() + .ok( + { + "message": message, + "deleted_count": deleted_count, + "failed_count": len(failed_items), + "failed_items": failed_items, + } + ) + .__dict__ + ) + else: + # 单个删除 + user_id = data.get("user_id") + cid = data.get("cid") + + if not user_id or not cid: + return Response().error("缺少必要参数: user_id 和 cid").__dict__ + + await self.core_lifecycle.conversation_manager.delete_conversation( + unified_msg_origin=user_id, conversation_id=cid + ) + return Response().ok({"message": "对话删除成功"}).__dict__ except Exception as e: logger.error(f"删除对话失败: {str(e)}\n{traceback.format_exc()}") diff --git a/dashboard/src/i18n/locales/en-US/features/conversation.json b/dashboard/src/i18n/locales/en-US/features/conversation.json index e577754e2..b7af64423 100644 --- a/dashboard/src/i18n/locales/en-US/features/conversation.json +++ b/dashboard/src/i18n/locales/en-US/features/conversation.json @@ -12,6 +12,13 @@ "title": "Conversation History", "refresh": "Refresh" }, + "batch": { + "deleteSelected": "Delete Selected ({count})" + }, + "pagination": { + "itemsPerPage": "Items per page", + "showingItems": "Showing {start}-{end} of {total} items" + }, "table": { "headers": { "title": "Conversation Title", @@ -61,6 +68,13 @@ "message": "Are you sure you want to delete conversation {title}? This action cannot be undone.", "cancel": "Cancel", "confirm": "Delete" + }, + "batchDelete": { + "title": "Batch Delete Confirmation", + "message": "Are you sure you want to delete the selected {count} conversations? This action cannot be undone, please proceed with caution!", + "andMore": "and {count} more", + "cancel": "Cancel", + "confirm": "Batch Delete" } }, "messages": { @@ -72,6 +86,10 @@ "historyError": "Failed to fetch conversation history", "historySaveSuccess": "Conversation history saved successfully", "historySaveError": "Failed to save conversation history", - "invalidJson": "Invalid JSON format" + "invalidJson": "Invalid JSON format", + "noItemSelected": "Please select conversations to delete first", + "batchDeleteSuccess": "Successfully deleted {count} conversations", + "batchDeleteError": "Batch delete failed", + "batchDeletePartial": "Delete completed: {deleted} successful, {failed} failed" } } \ No newline at end of file diff --git a/dashboard/src/i18n/locales/zh-CN/features/conversation.json b/dashboard/src/i18n/locales/zh-CN/features/conversation.json index 17c2e1245..2888e21f0 100644 --- a/dashboard/src/i18n/locales/zh-CN/features/conversation.json +++ b/dashboard/src/i18n/locales/zh-CN/features/conversation.json @@ -12,6 +12,13 @@ "title": "对话历史", "refresh": "刷新" }, + "batch": { + "deleteSelected": "删除选中 ({count})" + }, + "pagination": { + "itemsPerPage": "每页", + "showingItems": "显示 {start}-{end} 项,共 {total} 项" + }, "table": { "headers": { "title": "对话标题", @@ -61,6 +68,13 @@ "message": "确定要删除对话 {title} 吗?此操作不可恢复。", "cancel": "取消", "confirm": "删除" + }, + "batchDelete": { + "title": "批量删除确认", + "message": "确定要删除选中的 {count} 个对话吗?此操作不可恢复,请谨慎操作!", + "andMore": "等 {count} 个", + "cancel": "取消", + "confirm": "批量删除" } }, "messages": { @@ -72,6 +86,10 @@ "historyError": "获取对话历史失败", "historySaveSuccess": "对话历史保存成功", "historySaveError": "对话历史保存失败", - "invalidJson": "JSON格式无效" + "invalidJson": "JSON格式无效", + "noItemSelected": "请先选择要删除的对话", + "batchDeleteSuccess": "成功删除 {count} 个对话", + "batchDeleteError": "批量删除失败", + "batchDeletePartial": "删除完成:成功 {deleted} 个,失败 {failed} 个" } } \ No newline at end of file diff --git a/dashboard/src/views/ConversationPage.vue b/dashboard/src/views/ConversationPage.vue index d632afd4a..fc7cc0d43 100644 --- a/dashboard/src/views/ConversationPage.vue +++ b/dashboard/src/views/ConversationPage.vue @@ -10,7 +10,7 @@ + density="compact" hide-details :disabled="loading">