From 65890e775cd4b890c681ca05f528ba8e1af4462c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=99=E5=A4=A7?= Date: Thu, 16 Apr 2026 23:43:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E9=A1=B5=E5=8A=9F=E8=83=BD=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D:=20-=20=E6=88=90=E4=BA=A4=E8=A1=8C=E6=83=85=E6=AF=8F?= =?UTF-8?q?=E9=A1=B5=E6=94=B9=E4=B8=BA300=E6=9D=A1=20-=20=E5=AF=BB?= =?UTF-8?q?=E9=85=8D=E5=8F=B7=E6=AF=8F=E9=A1=B5=E6=94=B9=E4=B8=BA300?= =?UTF-8?q?=E6=9D=A1=20-=20=E5=90=8E=E7=AB=AF=E8=BF=94=E5=9B=9EX-Total-Pag?= =?UTF-8?q?es=E5=A4=B4=E6=94=AF=E6=8C=81=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/routers/deal.py | 9 ++++++++- backend/app/routers/information.py | 14 ++++++++++++-- frontend/src/pages/News.jsx | 4 ++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/backend/app/routers/deal.py b/backend/app/routers/deal.py index 4817aff..ae352cb 100644 --- a/backend/app/routers/deal.py +++ b/backend/app/routers/deal.py @@ -110,9 +110,16 @@ def get_deal_list( # 分页 offset = (page - 1) * page_size + total_count = query.count() + total_pages = (total_count + page_size - 1) // page_size items = query.offset(offset).limit(page_size).all() - return items + # 返回Response对象以添加自定义头 + from fastapi.responses import JSONResponse + return JSONResponse( + content=[DealInfoResponse.model_validate(item).model_dump() for item in items], + headers={"X-Total-Pages": str(total_pages), "X-Total-Count": str(total_count)} + ) @router.get("/stats") def get_deal_stats( diff --git a/backend/app/routers/information.py b/backend/app/routers/information.py index 5a8c00f..d909d01 100644 --- a/backend/app/routers/information.py +++ b/backend/app/routers/information.py @@ -1019,6 +1019,8 @@ def get_seek_list_all( status: str = Query("active"), user_id: Optional[str] = None, user_only: bool = Query(False), + page: int = Query(1, ge=1), + page_size: int = Query(100, ge=1, le=1000), current_user: Optional[User] = Depends(get_current_user), db: Session = Depends(get_db) ): @@ -1034,7 +1036,11 @@ def get_seek_list_all( if user_id: query = query.filter(Information.user_id == user_id) - items = query.order_by(Information.created_at.desc()).all() + # 计算总数和分页 + total_count = query.count() + total_pages = (total_count + page_size - 1) // page_size + offset = (page - 1) * page_size + items = query.order_by(Information.created_at.desc()).offset(offset).limit(page_size).all() result = [] for item in items: @@ -1071,4 +1077,8 @@ def get_seek_list_all( "network_matched_count": network_matched_count }) - return result + from fastapi.responses import JSONResponse + return JSONResponse( + content=result, + headers={"X-Total-Pages": str(total_pages), "X-Total-Count": str(total_count)} + ) diff --git a/frontend/src/pages/News.jsx b/frontend/src/pages/News.jsx index 69686df..ef61947 100644 --- a/frontend/src/pages/News.jsx +++ b/frontend/src/pages/News.jsx @@ -88,12 +88,12 @@ export default function News() { // 成交行情和寻配号每页100条(后端限制最大100) if (activeTab === 'deal') { - url += (url.includes('?') ? '&' : '?') + 'page_size=100' + url += (url.includes('?') ? '&' : '?') + 'page_size=300' if (dealDate) { url += '&deal_date=' + dealDate } } else if (activeTab === 'seek') { - url += (url.includes("?") ? "&" : "?") + "page=" + currentPage + "&page_size=100" + url += (url.includes("?") ? "&" : "?") + "page=" + currentPage + "&page_size=300" } const res = await fetch(url, { headers })