feat: Cookie管理页面增加批量删除功能
This commit is contained in:
@@ -139,3 +139,24 @@ def delete_cookie(
|
||||
task.message = "Cookie已清除"
|
||||
db.commit()
|
||||
return {"message": "已删除", "success": True}
|
||||
|
||||
|
||||
@router.delete("/batch")
|
||||
def delete_cookies_batch(
|
||||
task_ids: str = "",
|
||||
db: Session = Depends(get_db),
|
||||
current: User = Depends(require_permission("cookie:export")),
|
||||
):
|
||||
"""批量删除 Cookie 记录。"""
|
||||
if not task_ids:
|
||||
raise HTTPException(status_code=400, detail="请指定记录ID")
|
||||
ids = [int(x) for x in task_ids.split(",") if x.strip().isdigit()]
|
||||
if not ids:
|
||||
raise HTTPException(status_code=400, detail="无效的ID")
|
||||
tasks = db.query(LoginTask).filter(LoginTask.id.in_(ids)).all()
|
||||
for t in tasks:
|
||||
t.cookie = ""
|
||||
t.status = "failed"
|
||||
t.message = "Cookie已清除"
|
||||
db.commit()
|
||||
return {"message": f"已删除 {len(tasks)} 条", "deleted": len(tasks), "success": True}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import api from './client';
|
||||
import type { CookieItem, MessageResponse } from './types';
|
||||
import type { CookieItem, MessageDeletedResponse, MessageResponse } from './types';
|
||||
|
||||
export const cookieApi = {
|
||||
list: () => api.get<CookieItem[], CookieItem[]>('/cookies'),
|
||||
exportCsv: (format?: string) => api.get<Blob, Blob>('/cookies/export', { responseType: 'blob', params: format ? { format } : {} }),
|
||||
delete: (id: number) => api.delete<MessageResponse, MessageResponse>(`/cookies/${id}`),
|
||||
deleteBatch: (ids: number[]) => api.delete<MessageDeletedResponse, MessageDeletedResponse>('/cookies/batch', { params: { task_ids: ids.join(',') } }),
|
||||
};
|
||||
|
||||
@@ -118,6 +118,22 @@ export default function CookiePage() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleDeleteSelected = async () => {
|
||||
if (selectedRowKeys.length === 0) {
|
||||
message.warning('请先选择要删除的 Cookie');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const ids = selectedRowKeys.map((k) => Number(k));
|
||||
const res = await cookieApi.deleteBatch(ids);
|
||||
message.success(res.message);
|
||||
setSelectedRowKeys([]);
|
||||
loadCookies();
|
||||
} catch (e: unknown) {
|
||||
message.error(getErrorMessage(e));
|
||||
}
|
||||
};
|
||||
|
||||
// 筛选
|
||||
const filteredCookies = cookies.filter((c) => {
|
||||
if (!searchText) return true;
|
||||
@@ -199,6 +215,21 @@ export default function CookiePage() {
|
||||
>
|
||||
复制选中 {selectedRowKeys.length > 0 && `(${selectedRowKeys.length})`}
|
||||
</Button>
|
||||
{canExport && (
|
||||
<Popconfirm
|
||||
title={`确认删除选中的 ${selectedRowKeys.length} 条 Cookie?`}
|
||||
onConfirm={handleDeleteSelected}
|
||||
disabled={selectedRowKeys.length === 0}
|
||||
>
|
||||
<Button
|
||||
danger
|
||||
icon={<DeleteOutlined />}
|
||||
disabled={selectedRowKeys.length === 0}
|
||||
>
|
||||
删除选中 {selectedRowKeys.length > 0 && `(${selectedRowKeys.length})`}
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
)}
|
||||
{canExport && (
|
||||
<Dropdown
|
||||
menu={{
|
||||
|
||||
Reference in New Issue
Block a user