前后端数据流对齐:
后端改动:
GET /api/v1/accounts 现在返回分页格式 {items, total, page, size, total_pages, status_counts},默认每页 12 个
批量操作用 size=500 一次拉全部
前端改动:
base.html — 加了移动端汉堡菜单、全局响应式样式、pagination disabled 状态
dashboard.html — 账号卡片分页,统计数据从 API 的 status_counts 取,移动端单列布局
account_detail.html — 签到记录改成上下两行布局(topic+状态 / 消息+时间),分页用统一的上一页/下一页样式,移动端适配
分页逻辑统一:前后端都用 page/total_pages 字段,pagination 组件显示当前页 ±2 页码。
This commit is contained in:
@@ -92,15 +92,49 @@ async def create_account(
|
||||
|
||||
@router.get("")
|
||||
async def list_accounts(
|
||||
page: int = 1,
|
||||
size: int = 12,
|
||||
user: User = Depends(get_current_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
from sqlalchemy import func as sa_func
|
||||
|
||||
# Total count
|
||||
count_q = select(sa_func.count()).select_from(
|
||||
select(Account).where(Account.user_id == user.id).subquery()
|
||||
)
|
||||
total = (await db.execute(count_q)).scalar() or 0
|
||||
|
||||
# Status counts (for dashboard stats)
|
||||
status_q = (
|
||||
select(Account.status, sa_func.count())
|
||||
.where(Account.user_id == user.id)
|
||||
.group_by(Account.status)
|
||||
)
|
||||
status_rows = (await db.execute(status_q)).all()
|
||||
status_counts = {row[0]: row[1] for row in status_rows}
|
||||
|
||||
# Paginated list
|
||||
offset = (max(1, page) - 1) * size
|
||||
result = await db.execute(
|
||||
select(Account).where(Account.user_id == user.id)
|
||||
select(Account)
|
||||
.where(Account.user_id == user.id)
|
||||
.order_by(Account.created_at.desc())
|
||||
.offset(offset)
|
||||
.limit(size)
|
||||
)
|
||||
accounts = result.scalars().all()
|
||||
total_pages = (total + size - 1) // size if total > 0 else 0
|
||||
|
||||
return success_response(
|
||||
[_account_to_dict(a) for a in accounts],
|
||||
{
|
||||
"items": [_account_to_dict(a) for a in accounts],
|
||||
"total": total,
|
||||
"page": page,
|
||||
"size": size,
|
||||
"total_pages": total_pages,
|
||||
"status_counts": status_counts,
|
||||
},
|
||||
"Accounts retrieved",
|
||||
)
|
||||
|
||||
|
||||
1
backend/task_scheduler/app/__init__.py
Normal file
1
backend/task_scheduler/app/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
# Task scheduler app
|
||||
1
backend/task_scheduler/app/tasks/__init__.py
Normal file
1
backend/task_scheduler/app/tasks/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
# Task modules
|
||||
Reference in New Issue
Block a user