From 446cd32484b4d2c58f00ea121400ccc7e4595d5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=99=E5=A4=A7?= Date: Fri, 17 Apr 2026 00:40:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=89=E4=B8=AA=E9=97=AE?= =?UTF-8?q?=E9=A2=98:=201.=20=E6=88=90=E4=BA=A4=E8=A1=8C=E6=83=85=E6=A0=87?= =?UTF-8?q?=E9=A2=98=E5=8E=BB=E6=8E=89=E6=8B=AC=E5=8F=B7=202.=20=E6=AF=8F?= =?UTF-8?q?=E9=A1=B5=E6=94=B9=E4=B8=BA500=E6=9D=A1=203.=20=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E9=A1=B5=E9=9D=A2=E6=98=BE=E7=A4=BA=E8=A1=8C=E6=83=85?= =?UTF-8?q?=E6=95=B0=E5=B9=B6=E5=8F=AF=E7=82=B9=E5=87=BB=E8=B7=B3=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/routers/deal.py | 2 +- backend/app/routers/users.py | 16 ++++++++++------ frontend/src/pages/Admin.jsx | 7 +++++-- frontend/src/pages/News.jsx | 11 ++++++++--- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/backend/app/routers/deal.py b/backend/app/routers/deal.py index ae352cb..d7a0212 100644 --- a/backend/app/routers/deal.py +++ b/backend/app/routers/deal.py @@ -117,7 +117,7 @@ def get_deal_list( # 返回Response对象以添加自定义头 from fastapi.responses import JSONResponse return JSONResponse( - content=[DealInfoResponse.model_validate(item).model_dump() for item in items], + content=[DealInfoResponse.model_validate(item).model_dump(mode='json') for item in items], headers={"X-Total-Pages": str(total_pages), "X-Total-Count": str(total_count)} ) diff --git a/backend/app/routers/users.py b/backend/app/routers/users.py index c8cf2da..d045a7f 100644 --- a/backend/app/routers/users.py +++ b/backend/app/routers/users.py @@ -5,6 +5,7 @@ from sqlalchemy.orm import Session from app.core.database import get_db from app.core.auth import get_current_user from app.models.models import User, Collection +from app.models.deal_info import DealInfo from app.schemas.schemas import UserResponse, UserUpdate router = APIRouter(prefix="/api", tags=["用户"]) @@ -97,7 +98,7 @@ def get_users( db: Session = Depends(get_db) ): """获取用户列表(仅管理员)""" - if current_user.role not in ["admin", "editor"]: + if not current_user or current_user.role not in ["admin", "editor"]: raise HTTPException(status_code=403, detail="无权访问") total = db.query(User).count() @@ -114,6 +115,8 @@ def get_users( for u in users: # 统计每个用户的藏品数量 count = db.query(Collection).filter(Collection.f99_91_user_id == u.f99_90_id).count() + # 统计每个用户的行情数量 + deal_count = db.query(DealInfo).filter(DealInfo.user_id == u.f99_90_id).count() user_list.append({ "id": u.f99_90_id, "username": u.f01_01_name, @@ -123,6 +126,7 @@ def get_users( "user_code": u.user_code, "created_at": u.f99_92_created_at.isoformat() if u.f99_92_created_at else None, "collectionCount": count, + "dealCount": deal_count, "level": u.f99_94_level, "aiCount": u.f99_95_ai_count, "searchCount": u.f99_96_search_count, @@ -143,7 +147,7 @@ def get_user( db: Session = Depends(get_db) ): """获取单个用户信息""" - if current_user.role not in ["admin", "editor"]: + if not current_user or current_user.role not in ["admin", "editor"]: raise HTTPException(status_code=403, detail="无权访问") user = db.query(User).filter(User.id == user_id).first() @@ -168,7 +172,7 @@ def get_user_collections( db: Session = Depends(get_db) ): """获取指定用户的藏品列表""" - if current_user.role not in ["admin", "editor"]: + if not current_user or current_user.role not in ["admin", "editor"]: raise HTTPException(status_code=403, detail="无权访问") collections = db.query(Collection).filter( @@ -185,7 +189,7 @@ def get_user_collection_count( db: Session = Depends(get_db) ): """获取指定用户的藏品数量""" - if current_user.role not in ["admin", "editor"]: + if not current_user or current_user.role not in ["admin", "editor"]: raise HTTPException(status_code=403, detail="E00050: 仅管理员可访问") count = db.query(Collection).filter(Collection.user_id == user_id).count() @@ -210,7 +214,7 @@ def update_user( db: Session = Depends(get_db) ): """更新用户信息(仅管理员)""" - if current_user.role not in ["admin", "editor"]: + if not current_user or current_user.role not in ["admin", "editor"]: raise HTTPException(status_code=403, detail="E00050: 仅管理员可访问") user = db.query(User).filter(User.f99_90_id == user_id).first() @@ -288,7 +292,7 @@ def delete_user( db: Session = Depends(get_db) ): """删除用户(仅管理员)""" - if current_user.role not in ["admin", "editor"]: + if not current_user or current_user.role not in ["admin", "editor"]: raise HTTPException(status_code=403, detail="E00050: 仅管理员可访问") # 不能删除自己 diff --git a/frontend/src/pages/Admin.jsx b/frontend/src/pages/Admin.jsx index a9c3728..ed3cef2 100644 --- a/frontend/src/pages/Admin.jsx +++ b/frontend/src/pages/Admin.jsx @@ -221,8 +221,11 @@ export default function Admin() {
-
藏品数
-
window.location.hash = '#/list?userId=' + user.id} title='点击查看'>{user.collectionCount || 0}
+
藏品数 | 行情数
+
+
window.location.hash = '#/list?userId=' + user.id} title='点击查看藏品'>{user.collectionCount || 0}
+
window.location.hash = '#/news?userId=' + user.id} title='点击查看行情'>{user.dealCount || 0}
+
{/* 更多字段 */} diff --git a/frontend/src/pages/News.jsx b/frontend/src/pages/News.jsx index ef61947..a8d2152 100644 --- a/frontend/src/pages/News.jsx +++ b/frontend/src/pages/News.jsx @@ -47,6 +47,10 @@ export default function News() { const [expandedItems, setExpandedItems] = useState({}) // 展开状态 const [loading, setLoading] = useState(false) const [currentPage, setCurrentPage] = useState(1) + const [urlUserId, setUrlUserId] = useState(() => { + const params = new URLSearchParams(window.location.hash.split("?")[1] || "") + return params.get("userId") || null + }) const [totalPages, setTotalPages] = useState(1) const API_BASE = localStorage.getItem('API_BASE') || '' @@ -88,12 +92,13 @@ export default function News() { // 成交行情和寻配号每页100条(后端限制最大100) if (activeTab === 'deal') { - url += (url.includes('?') ? '&' : '?') + 'page_size=300' + url += (url.includes('?') ? '&' : '?') + 'page_size=500' + if (urlUserId) { url += "&user_id=" + urlUserId } if (dealDate) { url += '&deal_date=' + dealDate } } else if (activeTab === 'seek') { - url += (url.includes("?") ? "&" : "?") + "page=" + currentPage + "&page_size=300" + url += (url.includes("?") ? "&" : "?") + "page=" + currentPage + "&page_size=500" } const res = await fetch(url, { headers }) @@ -492,7 +497,7 @@ export default function News() { )}

- {activeTab === 'seek' ? '寻配号信息' : activeTab === 'deal' ? `成交行情信息 (${dealDate})` : '一尘看板'} + {activeTab === 'seek' ? '寻配号信息' : activeTab === 'deal' ? `成交行情信息 ${dealDate}` : '一尘看板'} {activeTab === 'seek' && (