sync: soul-admin 前端、soul-admin 页面 | 原因: 前端代码修改、前端页面修改
This commit is contained in:
@@ -92,11 +92,37 @@ export function CKBStatsTab({ onSwitchTab }: CKBStatsTabProps = {}) {
|
||||
try {
|
||||
const data = await get<{ success?: boolean; data?: MatchStats }>('/api/db/match-records?stats=true')
|
||||
if (data?.success && data.data) {
|
||||
setStats(data.data)
|
||||
let result = data.data
|
||||
// 后端 GORM bug 导致 uniqueUsers=0 时,前端自行计算
|
||||
if (result.totalMatches > 0 && (!result.uniqueUsers || result.uniqueUsers === 0)) {
|
||||
try {
|
||||
const allRec = await get<{ success?: boolean; records?: { userId: string }[]; total?: number }>(
|
||||
'/api/db/match-records?page=1&pageSize=200'
|
||||
)
|
||||
if (allRec?.success && allRec.records) {
|
||||
const userSet = new Set(allRec.records.map(r => r.userId).filter(Boolean))
|
||||
result = { ...result, uniqueUsers: userSet.size, totalMatches: allRec.total ?? result.totalMatches }
|
||||
}
|
||||
} catch { /* ignore fallback error */ }
|
||||
}
|
||||
setStats(result)
|
||||
} else {
|
||||
const fallback = await get<{ success?: boolean; total?: number }>('/api/db/match-records?page=1&pageSize=1')
|
||||
const fallback = await get<{ success?: boolean; records?: { userId: string; matchType: string; createdAt: string }[]; total?: number }>(
|
||||
'/api/db/match-records?page=1&pageSize=200'
|
||||
)
|
||||
if (fallback?.success) {
|
||||
setStats({ totalMatches: fallback.total ?? 0, todayMatches: 0, byType: [], uniqueUsers: 0 })
|
||||
const records = fallback.records || []
|
||||
const userSet = new Set(records.map(r => r.userId).filter(Boolean))
|
||||
const today = new Date().toISOString().slice(0, 10)
|
||||
const todayCount = records.filter(r => r.createdAt?.startsWith(today)).length
|
||||
const typeMap: Record<string, number> = {}
|
||||
records.forEach(r => { if (r.matchType) typeMap[r.matchType] = (typeMap[r.matchType] || 0) + 1 })
|
||||
setStats({
|
||||
totalMatches: fallback.total ?? records.length,
|
||||
todayMatches: todayCount,
|
||||
byType: Object.entries(typeMap).map(([matchType, count]) => ({ matchType, count })),
|
||||
uniqueUsers: userSet.size,
|
||||
})
|
||||
}
|
||||
}
|
||||
} catch (e) { console.error('加载统计失败:', e) }
|
||||
|
||||
Reference in New Issue
Block a user