优化登录任务界面 + 修复时间显示 + 增加删除功能
- 筛选栏改为单行横排,概览精简为一行文字 - 任务列表全宽展示,日志移到底部可折叠 - 页面使用百分比布局,一屏展示无外层滚动 - 登录任务增加单条删除和批量删除功能 - 后端: datetime.utcnow 替换为 datetime.now(timezone.utc) - 后端: schemas 序列化统一输出带时区 ISO 格式 - 前端: 新增 utils/time.ts 统一时间格式化工具 - 前端: CookiePage/LoginTasksPage 时间列使用 formatTime() Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
8771d91a30
commit
72bcd1274c
@@ -1,5 +1,6 @@
|
||||
"""Cookie 管理路由"""
|
||||
|
||||
from datetime import timezone
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from fastapi.responses import StreamingResponse
|
||||
from sqlalchemy.orm import Session
|
||||
@@ -11,6 +12,15 @@ from ..models import User, LoginTask, Account
|
||||
from ..deps import get_current_user, require_permission
|
||||
from ..permissions import has_permission
|
||||
|
||||
|
||||
def _fmt_dt(dt) -> str | None:
|
||||
"""将 datetime 格式化为带时区的 ISO 字符串。"""
|
||||
if dt is None:
|
||||
return None
|
||||
if dt.tzinfo is None:
|
||||
dt = dt.replace(tzinfo=timezone.utc)
|
||||
return dt.isoformat()
|
||||
|
||||
router = APIRouter(prefix="/api/cookies", tags=["Cookie管理"])
|
||||
|
||||
|
||||
@@ -39,7 +49,7 @@ def list_cookies(
|
||||
"account_username": acc.username if acc else "",
|
||||
"assigned_to": acc.assigned_to,
|
||||
"assigned_username": acc.assigned_user.username if acc and acc.assigned_user else None,
|
||||
"created_at": t.finished_at.isoformat() if t.finished_at else None,
|
||||
"created_at": _fmt_dt(t.finished_at),
|
||||
}
|
||||
# 只有有 cookie:view 权限才返回 cookie 内容
|
||||
if has_permission(current.role, "cookie:view"):
|
||||
@@ -70,7 +80,7 @@ def export_cookies(
|
||||
for t in tasks:
|
||||
acc = db.query(Account).filter(Account.id == t.account_id).first()
|
||||
username = acc.username if acc else ""
|
||||
writer.writerow([username, t.cookie or "", t.finished_at.isoformat() if t.finished_at else ""])
|
||||
writer.writerow([username, t.cookie or "", _fmt_dt(t.finished_at) or ""])
|
||||
|
||||
output.seek(0)
|
||||
return StreamingResponse(
|
||||
|
||||
@@ -111,6 +111,38 @@ def list_tasks(
|
||||
return result
|
||||
|
||||
|
||||
@router.delete("/tasks/{task_id}")
|
||||
def delete_task(
|
||||
task_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current: User = Depends(require_permission("login:batch")),
|
||||
):
|
||||
"""删除单个登录任务。"""
|
||||
task = db.query(LoginTask).filter(LoginTask.id == task_id).first()
|
||||
if not task:
|
||||
raise HTTPException(status_code=404, detail="任务不存在")
|
||||
db.delete(task)
|
||||
db.commit()
|
||||
return {"message": "已删除", "success": True}
|
||||
|
||||
|
||||
@router.delete("/tasks")
|
||||
def delete_tasks(
|
||||
task_ids: str = "",
|
||||
db: Session = Depends(get_db),
|
||||
current: User = Depends(require_permission("login:batch")),
|
||||
):
|
||||
"""批量删除登录任务。"""
|
||||
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")
|
||||
deleted = db.query(LoginTask).filter(LoginTask.id.in_(ids)).delete(synchronize_session=False)
|
||||
db.commit()
|
||||
return {"message": f"已删除 {deleted} 个任务", "deleted": deleted, "success": True}
|
||||
|
||||
|
||||
@router.post("/stop/{batch_id}")
|
||||
def stop_batch(
|
||||
batch_id: str,
|
||||
|
||||
Reference in New Issue
Block a user