分页功能修复:
- 成交行情每页改为300条 - 寻配号每页改为300条 - 后端返回X-Total-Pages头支持分页
This commit is contained in:
parent
7939abc60a
commit
65890e775c
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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)}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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 })
|
||||
|
|
|
|||
Loading…
Reference in New Issue