From a21f7d650b12afedec5d0a80e936d6c9f5622b6b Mon Sep 17 00:00:00 2001 From: erio Date: Sat, 7 Mar 2026 00:18:41 +0800 Subject: [PATCH] feat: display daily/weekly/total quota dimensions in account list - Add quota_daily_limit/used and quota_weekly_limit/used to DTO and frontend Account type - AccountCapacityCell shows D (daily), W (weekly), and $ (total) badges with color-coded status (green/yellow/red) - AccountActionMenu shows reset button when any quota dimension is set - Extract quotaBadgeClass/quotaBadgeTooltip as shared functions Co-Authored-By: Claude Opus 4.6 --- backend/internal/handler/dto/mappers.go | 14 ++- backend/internal/handler/dto/types.go | 8 +- .../account/AccountCapacityCell.vue | 113 +++++++++++++----- .../admin/account/AccountActionMenu.vue | 8 +- frontend/src/types/index.ts | 4 + 5 files changed, 109 insertions(+), 38 deletions(-) diff --git a/backend/internal/handler/dto/mappers.go b/backend/internal/handler/dto/mappers.go index c21ff57d98..c3b9f78554 100644 --- a/backend/internal/handler/dto/mappers.go +++ b/backend/internal/handler/dto/mappers.go @@ -260,11 +260,19 @@ func AccountFromServiceShallow(a *service.Account) *Account { if a.Type == service.AccountTypeAPIKey { if limit := a.GetQuotaLimit(); limit > 0 { out.QuotaLimit = &limit - } - used := a.GetQuotaUsed() - if out.QuotaLimit != nil { + used := a.GetQuotaUsed() out.QuotaUsed = &used } + if limit := a.GetQuotaDailyLimit(); limit > 0 { + out.QuotaDailyLimit = &limit + used := a.GetQuotaDailyUsed() + out.QuotaDailyUsed = &used + } + if limit := a.GetQuotaWeeklyLimit(); limit > 0 { + out.QuotaWeeklyLimit = &limit + used := a.GetQuotaWeeklyUsed() + out.QuotaWeeklyUsed = &used + } } return out diff --git a/backend/internal/handler/dto/types.go b/backend/internal/handler/dto/types.go index 3626bda982..c2bb849feb 100644 --- a/backend/internal/handler/dto/types.go +++ b/backend/internal/handler/dto/types.go @@ -193,8 +193,12 @@ type Account struct { ClientAffinityEnabled *bool `json:"client_affinity_enabled,omitempty"` // API Key 账号配额限制 - QuotaLimit *float64 `json:"quota_limit,omitempty"` - QuotaUsed *float64 `json:"quota_used,omitempty"` + QuotaLimit *float64 `json:"quota_limit,omitempty"` + QuotaUsed *float64 `json:"quota_used,omitempty"` + QuotaDailyLimit *float64 `json:"quota_daily_limit,omitempty"` + QuotaDailyUsed *float64 `json:"quota_daily_used,omitempty"` + QuotaWeeklyLimit *float64 `json:"quota_weekly_limit,omitempty"` + QuotaWeeklyUsed *float64 `json:"quota_weekly_used,omitempty"` Proxy *Proxy `json:"proxy,omitempty"` AccountGroups []AccountGroup `json:"account_groups,omitempty"` diff --git a/frontend/src/components/account/AccountCapacityCell.vue b/frontend/src/components/account/AccountCapacityCell.vue index 2001b185e3..27c7ef3561 100644 --- a/frontend/src/components/account/AccountCapacityCell.vue +++ b/frontend/src/components/account/AccountCapacityCell.vue @@ -72,19 +72,51 @@ - -
+ +
+ D + ${{ formatCost(account.quota_daily_used) }} + / + ${{ formatCost(account.quota_daily_limit) }} + +
+ + +
+ + W + ${{ formatCost(account.quota_weekly_used) }} + / + ${{ formatCost(account.quota_weekly_limit) }} + +
+ + +
+ - ${{ formatCost(currentQuotaUsed) }} + ${{ formatCost(account.quota_used) }} / ${{ formatCost(account.quota_limit) }} @@ -304,26 +336,54 @@ const rpmTooltip = computed(() => { } }) -// 是否显示配额限制(仅 apikey 类型且设置了 quota_limit) -const showQuotaLimit = computed(() => { - return ( - props.account.type === 'apikey' && - props.account.quota_limit !== undefined && - props.account.quota_limit !== null && - props.account.quota_limit > 0 - ) +// ====== 日配额 ====== +const showDailyQuota = computed(() => { + return props.account.type === 'apikey' && + props.account.quota_daily_limit != null && + props.account.quota_daily_limit > 0 }) -// 当前已用配额 -const currentQuotaUsed = computed(() => props.account.quota_used ?? 0) +const dailyQuotaClass = computed(() => + quotaBadgeClass(props.account.quota_daily_used ?? 0, props.account.quota_daily_limit ?? 0) +) -// 配额状态样式 -const quotaClass = computed(() => { - if (!showQuotaLimit.value) return '' +const dailyQuotaTooltip = computed(() => + quotaBadgeTooltip(props.account.quota_daily_used ?? 0, props.account.quota_daily_limit ?? 0) +) - const used = currentQuotaUsed.value - const limit = props.account.quota_limit || 0 +// ====== 周配额 ====== +const showWeeklyQuota = computed(() => { + return props.account.type === 'apikey' && + props.account.quota_weekly_limit != null && + props.account.quota_weekly_limit > 0 +}) +const weeklyQuotaClass = computed(() => + quotaBadgeClass(props.account.quota_weekly_used ?? 0, props.account.quota_weekly_limit ?? 0) +) + +const weeklyQuotaTooltip = computed(() => + quotaBadgeTooltip(props.account.quota_weekly_used ?? 0, props.account.quota_weekly_limit ?? 0) +) + +// ====== 总配额 ====== +const showTotalQuota = computed(() => { + return props.account.type === 'apikey' && + props.account.quota_limit != null && + props.account.quota_limit > 0 +}) + +const totalQuotaClass = computed(() => + quotaBadgeClass(props.account.quota_used ?? 0, props.account.quota_limit ?? 0) +) + +const totalQuotaTooltip = computed(() => + quotaBadgeTooltip(props.account.quota_used ?? 0, props.account.quota_limit ?? 0) +) + +// ====== 配额公共逻辑 ====== +function quotaBadgeClass(used: number, limit: number): string { + if (limit <= 0) return '' if (used >= limit) { return 'bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400' } @@ -331,20 +391,15 @@ const quotaClass = computed(() => { return 'bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400' } return 'bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-400' -}) - -// 配额提示文字 -const quotaTooltip = computed(() => { - if (!showQuotaLimit.value) return '' - - const used = currentQuotaUsed.value - const limit = props.account.quota_limit || 0 +} +function quotaBadgeTooltip(used: number, limit: number): string { + if (limit <= 0) return '' if (used >= limit) { return t('admin.accounts.capacity.quota.exceeded') } return t('admin.accounts.capacity.quota.normal') -}) +} // 格式化费用显示 const formatCost = (value: number | null | undefined) => { diff --git a/frontend/src/components/admin/account/AccountActionMenu.vue b/frontend/src/components/admin/account/AccountActionMenu.vue index 02596b9f7d..d84528bce1 100644 --- a/frontend/src/components/admin/account/AccountActionMenu.vue +++ b/frontend/src/components/admin/account/AccountActionMenu.vue @@ -76,10 +76,10 @@ const isRateLimited = computed(() => { }) const isOverloaded = computed(() => props.account?.overload_until && new Date(props.account.overload_until) > new Date()) const hasQuotaLimit = computed(() => { - return props.account?.type === 'apikey' && - props.account?.quota_limit !== undefined && - props.account?.quota_limit !== null && - props.account?.quota_limit > 0 + if (props.account?.type !== 'apikey') return false + return (props.account?.quota_limit != null && props.account.quota_limit > 0) || + (props.account?.quota_daily_limit != null && props.account.quota_daily_limit > 0) || + (props.account?.quota_weekly_limit != null && props.account.quota_weekly_limit > 0) }) const handleKeydown = (event: KeyboardEvent) => { diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.ts index ff61120d7c..a9704afaf6 100644 --- a/frontend/src/types/index.ts +++ b/frontend/src/types/index.ts @@ -717,6 +717,10 @@ export interface Account { // API Key 账号配额限制 quota_limit?: number | null quota_used?: number | null + quota_daily_limit?: number | null + quota_daily_used?: number | null + quota_weekly_limit?: number | null + quota_weekly_used?: number | null // 运行时状态(仅当启用对应限制时返回) current_window_cost?: number | null // 当前窗口费用