修复三个问题:

1. 成交行情标题去掉括号
2. 每页改为500条
3. 管理页面显示行情数并可点击跳转
This commit is contained in:
龙大 2026-04-17 00:40:29 +08:00
parent 65890e775c
commit 446cd32484
4 changed files with 24 additions and 12 deletions

View File

@ -117,7 +117,7 @@ def get_deal_list(
# 返回Response对象以添加自定义头 # 返回Response对象以添加自定义头
from fastapi.responses import JSONResponse from fastapi.responses import JSONResponse
return 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)} headers={"X-Total-Pages": str(total_pages), "X-Total-Count": str(total_count)}
) )

View File

@ -5,6 +5,7 @@ from sqlalchemy.orm import Session
from app.core.database import get_db from app.core.database import get_db
from app.core.auth import get_current_user from app.core.auth import get_current_user
from app.models.models import User, Collection from app.models.models import User, Collection
from app.models.deal_info import DealInfo
from app.schemas.schemas import UserResponse, UserUpdate from app.schemas.schemas import UserResponse, UserUpdate
router = APIRouter(prefix="/api", tags=["用户"]) router = APIRouter(prefix="/api", tags=["用户"])
@ -97,7 +98,7 @@ def get_users(
db: Session = Depends(get_db) 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="无权访问") raise HTTPException(status_code=403, detail="无权访问")
total = db.query(User).count() total = db.query(User).count()
@ -114,6 +115,8 @@ def get_users(
for u in users: for u in users:
# 统计每个用户的藏品数量 # 统计每个用户的藏品数量
count = db.query(Collection).filter(Collection.f99_91_user_id == u.f99_90_id).count() 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({ user_list.append({
"id": u.f99_90_id, "id": u.f99_90_id,
"username": u.f01_01_name, "username": u.f01_01_name,
@ -123,6 +126,7 @@ def get_users(
"user_code": u.user_code, "user_code": u.user_code,
"created_at": u.f99_92_created_at.isoformat() if u.f99_92_created_at else None, "created_at": u.f99_92_created_at.isoformat() if u.f99_92_created_at else None,
"collectionCount": count, "collectionCount": count,
"dealCount": deal_count,
"level": u.f99_94_level, "level": u.f99_94_level,
"aiCount": u.f99_95_ai_count, "aiCount": u.f99_95_ai_count,
"searchCount": u.f99_96_search_count, "searchCount": u.f99_96_search_count,
@ -143,7 +147,7 @@ def get_user(
db: Session = Depends(get_db) 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="无权访问") raise HTTPException(status_code=403, detail="无权访问")
user = db.query(User).filter(User.id == user_id).first() user = db.query(User).filter(User.id == user_id).first()
@ -168,7 +172,7 @@ def get_user_collections(
db: Session = Depends(get_db) 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="无权访问") raise HTTPException(status_code=403, detail="无权访问")
collections = db.query(Collection).filter( collections = db.query(Collection).filter(
@ -185,7 +189,7 @@ def get_user_collection_count(
db: Session = Depends(get_db) 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: 仅管理员可访问") raise HTTPException(status_code=403, detail="E00050: 仅管理员可访问")
count = db.query(Collection).filter(Collection.user_id == user_id).count() count = db.query(Collection).filter(Collection.user_id == user_id).count()
@ -210,7 +214,7 @@ def update_user(
db: Session = Depends(get_db) 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: 仅管理员可访问") raise HTTPException(status_code=403, detail="E00050: 仅管理员可访问")
user = db.query(User).filter(User.f99_90_id == user_id).first() user = db.query(User).filter(User.f99_90_id == user_id).first()
@ -288,7 +292,7 @@ def delete_user(
db: Session = Depends(get_db) 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: 仅管理员可访问") raise HTTPException(status_code=403, detail="E00050: 仅管理员可访问")
# 不能删除自己 # 不能删除自己

View File

@ -221,8 +221,11 @@ export default function Admin() {
</div> </div>
</div> </div>
<div style={{ textAlign: 'right' }}> <div style={{ textAlign: 'right' }}>
<div style={{ color: '#94a3b8', fontSize: '12px' }}>藏品数</div> <div style={{ color: '#94a3b8', fontSize: '12px' }}>藏品数 | 行情数</div>
<div style={{ color: '#60a5fa', fontSize: '20px', fontWeight: 'bold', cursor: 'pointer' }} onClick={() => window.location.hash = '#/list?userId=' + user.id} title='点击查看'>{user.collectionCount || 0}</div> <div style={{ display: 'flex', gap: '12px', justifyContent: 'flex-end', alignItems: 'center' }}>
<div style={{ color: '#60a5fa', fontSize: '20px', fontWeight: 'bold', cursor: 'pointer' }} onClick={() => window.location.hash = '#/list?userId=' + user.id} title='点击查看藏品'>{user.collectionCount || 0}</div>
<div style={{ color: '#22c55e', fontSize: '20px', fontWeight: 'bold', cursor: 'pointer' }} onClick={() => window.location.hash = '#/news?userId=' + user.id} title='点击查看行情'>{user.dealCount || 0}</div>
</div>
</div> </div>
</div> </div>
{/* 更多字段 */} {/* 更多字段 */}

View File

@ -47,6 +47,10 @@ export default function News() {
const [expandedItems, setExpandedItems] = useState({}) // const [expandedItems, setExpandedItems] = useState({}) //
const [loading, setLoading] = useState(false) const [loading, setLoading] = useState(false)
const [currentPage, setCurrentPage] = useState(1) 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 [totalPages, setTotalPages] = useState(1)
const API_BASE = localStorage.getItem('API_BASE') || '' const API_BASE = localStorage.getItem('API_BASE') || ''
@ -88,12 +92,13 @@ export default function News() {
// 100100 // 100100
if (activeTab === 'deal') { if (activeTab === 'deal') {
url += (url.includes('?') ? '&' : '?') + 'page_size=300' url += (url.includes('?') ? '&' : '?') + 'page_size=500'
if (urlUserId) { url += "&user_id=" + urlUserId }
if (dealDate) { if (dealDate) {
url += '&deal_date=' + dealDate url += '&deal_date=' + dealDate
} }
} else if (activeTab === 'seek') { } 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 }) const res = await fetch(url, { headers })
@ -492,7 +497,7 @@ export default function News() {
</div> </div>
)} )}
<h3 style={{ color: '#fff', marginBottom: '16px' }}> <h3 style={{ color: '#fff', marginBottom: '16px' }}>
{activeTab === 'seek' ? '寻配号信息' : activeTab === 'deal' ? `成交行情信息 (${dealDate})` : '一尘看板'} {activeTab === 'seek' ? '寻配号信息' : activeTab === 'deal' ? `成交行情信息 ${dealDate}` : '一尘看板'}
{activeTab === 'seek' && ( {activeTab === 'seek' && (
<div style={{ display: 'flex', gap: '8px', marginLeft: 'auto' }}> <div style={{ display: 'flex', gap: '8px', marginLeft: 'auto' }}>
<button onClick={() => { setViewMode('all'); fetchInfoList(); }} style={{ padding: '6px 12px', background: viewMode==='all'?'#3b82f6':'#1e293b', border: '1px solid #334155', borderRadius: '6px', color: '#fff', fontSize: '12px' }}>全部</button> <button onClick={() => { setViewMode('all'); fetchInfoList(); }} style={{ padding: '6px 12px', background: viewMode==='all'?'#3b82f6':'#1e293b', border: '1px solid #334155', borderRadius: '6px', color: '#fff', fontSize: '12px' }}>全部</button>