Merge pull request #951 from wanXcode/fix/dashboard-user-trend-label

fix(dashboard): prefer username over email prefix in recent usage chart
This commit is contained in:
Wesley Liddick
2026-03-13 22:56:13 +08:00
committed by GitHub
4 changed files with 20 additions and 11 deletions

View File

@@ -1155,6 +1155,7 @@ export interface UserUsageTrendPoint {
date: string
user_id: number
email: string
username: string
requests: number
tokens: number
cost: number // 标准计费

View File

@@ -412,23 +412,29 @@ const lineOptions = computed(() => ({
const userTrendChartData = computed(() => {
if (!userTrend.value?.length) return null
// Extract display name from email (part before @)
const getDisplayName = (email: string, userId: number): string => {
if (email && email.includes('@')) {
return email.split('@')[0]
const getDisplayName = (point: UserUsageTrendPoint): string => {
const username = point.username?.trim()
if (username) {
return username
}
return t('admin.redeem.userPrefix', { id: userId })
const email = point.email?.trim()
if (email) {
return email
}
return t('admin.redeem.userPrefix', { id: point.user_id })
}
// Group by user
const userGroups = new Map<string, { name: string; data: Map<string, number> }>()
// Group by user_id to avoid merging different users with the same display name
const userGroups = new Map<number, { name: string; data: Map<string, number> }>()
const allDates = new Set<string>()
userTrend.value.forEach((point) => {
allDates.add(point.date)
const key = getDisplayName(point.email, point.user_id)
const key = point.user_id
if (!userGroups.has(key)) {
userGroups.set(key, { name: key, data: new Map() })
userGroups.set(key, { name: getDisplayName(point), data: new Map() })
}
userGroups.get(key)!.data.set(point.date, point.tokens)
})