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 })