mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-11-20 15:06:36 +00:00
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
33ab8413db
commit
a21f7d650b
5 files changed
+109
-38
No files matched your search
@@ -260,11 +260,19 @@ func AccountFromServiceShallow(a *service.Account) *Account {
|
|||||||
if a.Type == service.AccountTypeAPIKey {
|
if a.Type == service.AccountTypeAPIKey {
|
||||||
if limit := a.GetQuotaLimit(); limit > 0 {
|
if limit := a.GetQuotaLimit(); limit > 0 {
|
||||||
out.QuotaLimit = &limit
|
out.QuotaLimit = &limit
|
||||||
}
|
used := a.GetQuotaUsed()
|
||||||
used := a.GetQuotaUsed()
|
|
||||||
if out.QuotaLimit != nil {
|
|
||||||
out.QuotaUsed = &used
|
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
|
return out
|
||||||
|
|||||||
@@ -193,8 +193,12 @@ type Account struct {
|
|||||||
ClientAffinityEnabled *bool `json:"client_affinity_enabled,omitempty"`
|
ClientAffinityEnabled *bool `json:"client_affinity_enabled,omitempty"`
|
||||||
|
|
||||||
// API Key 账号配额限制
|
// API Key 账号配额限制
|
||||||
QuotaLimit *float64 `json:"quota_limit,omitempty"`
|
QuotaLimit *float64 `json:"quota_limit,omitempty"`
|
||||||
QuotaUsed *float64 `json:"quota_used,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"`
|
Proxy *Proxy `json:"proxy,omitempty"`
|
||||||
AccountGroups []AccountGroup `json:"account_groups,omitempty"`
|
AccountGroups []AccountGroup `json:"account_groups,omitempty"`
|
||||||
|
|||||||
@@ -72,19 +72,51 @@
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- API Key 账号配额限制 -->
|
<!-- API Key 账号配额限制:日额度 -->
|
||||||
<div v-if="showQuotaLimit" class="flex items-center gap-1">
|
<div v-if="showDailyQuota" class="flex items-center gap-1">
|
||||||
<span
|
<span
|
||||||
:class="[
|
:class="[
|
||||||
'inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium',
|
'inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium',
|
||||||
quotaClass
|
dailyQuotaClass
|
||||||
]"
|
]"
|
||||||
:title="quotaTooltip"
|
:title="dailyQuotaTooltip"
|
||||||
|
>
|
||||||
|
<span class="font-semibold opacity-70">D</span>
|
||||||
|
<span class="font-mono">${{ formatCost(account.quota_daily_used) }}</span>
|
||||||
|
<span class="text-gray-400 dark:text-gray-500">/</span>
|
||||||
|
<span class="font-mono">${{ formatCost(account.quota_daily_limit) }}</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- API Key 账号配额限制:周额度 -->
|
||||||
|
<div v-if="showWeeklyQuota" class="flex items-center gap-1">
|
||||||
|
<span
|
||||||
|
:class="[
|
||||||
|
'inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium',
|
||||||
|
weeklyQuotaClass
|
||||||
|
]"
|
||||||
|
:title="weeklyQuotaTooltip"
|
||||||
|
>
|
||||||
|
<span class="font-semibold opacity-70">W</span>
|
||||||
|
<span class="font-mono">${{ formatCost(account.quota_weekly_used) }}</span>
|
||||||
|
<span class="text-gray-400 dark:text-gray-500">/</span>
|
||||||
|
<span class="font-mono">${{ formatCost(account.quota_weekly_limit) }}</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- API Key 账号配额限制:总额度 -->
|
||||||
|
<div v-if="showTotalQuota" class="flex items-center gap-1">
|
||||||
|
<span
|
||||||
|
:class="[
|
||||||
|
'inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium',
|
||||||
|
totalQuotaClass
|
||||||
|
]"
|
||||||
|
:title="totalQuotaTooltip"
|
||||||
>
|
>
|
||||||
<svg class="h-2.5 w-2.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
<svg class="h-2.5 w-2.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||||
<path stroke-linecap="round" stroke-linejoin="round" d="M2.25 18.75a60.07 60.07 0 0115.797 2.101c.727.198 1.453-.342 1.453-1.096V18.75M3.75 4.5v.75A.75.75 0 013 6h-.75m0 0v-.375c0-.621.504-1.125 1.125-1.125H20.25M2.25 6v9m18-10.5v.75c0 .414.336.75.75.75h.75m-1.5-1.5h.375c.621 0 1.125.504 1.125 1.125v9.75c0 .621-.504 1.125-1.125 1.125h-.375m1.5-1.5H21a.75.75 0 00-.75.75v.75m0 0H3.75m0 0h-.375a1.125 1.125 0 01-1.125-1.125V15m1.5 1.5v-.75A.75.75 0 003 15h-.75M15 10.5a3 3 0 11-6 0 3 3 0 016 0zm3 0h.008v.008H18V10.5zm-12 0h.008v.008H6V10.5z" />
|
<path stroke-linecap="round" stroke-linejoin="round" d="M2.25 18.75a60.07 60.07 0 0115.797 2.101c.727.198 1.453-.342 1.453-1.096V18.75M3.75 4.5v.75A.75.75 0 013 6h-.75m0 0v-.375c0-.621.504-1.125 1.125-1.125H20.25M2.25 6v9m18-10.5v.75c0 .414.336.75.75.75h.75m-1.5-1.5h.375c.621 0 1.125.504 1.125 1.125v9.75c0 .621-.504 1.125-1.125 1.125h-.375m1.5-1.5H21a.75.75 0 00-.75.75v.75m0 0H3.75m0 0h-.375a1.125 1.125 0 01-1.125-1.125V15m1.5 1.5v-.75A.75.75 0 003 15h-.75M15 10.5a3 3 0 11-6 0 3 3 0 016 0zm3 0h.008v.008H18V10.5zm-12 0h.008v.008H6V10.5z" />
|
||||||
</svg>
|
</svg>
|
||||||
<span class="font-mono">${{ formatCost(currentQuotaUsed) }}</span>
|
<span class="font-mono">${{ formatCost(account.quota_used) }}</span>
|
||||||
<span class="text-gray-400 dark:text-gray-500">/</span>
|
<span class="text-gray-400 dark:text-gray-500">/</span>
|
||||||
<span class="font-mono">${{ formatCost(account.quota_limit) }}</span>
|
<span class="font-mono">${{ formatCost(account.quota_limit) }}</span>
|
||||||
</span>
|
</span>
|
||||||
@@ -304,26 +336,54 @@ const rpmTooltip = computed(() => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// 是否显示配额限制(仅 apikey 类型且设置了 quota_limit)
|
// ====== 日配额 ======
|
||||||
const showQuotaLimit = computed(() => {
|
const showDailyQuota = computed(() => {
|
||||||
return (
|
return props.account.type === 'apikey' &&
|
||||||
props.account.type === 'apikey' &&
|
props.account.quota_daily_limit != null &&
|
||||||
props.account.quota_limit !== undefined &&
|
props.account.quota_daily_limit > 0
|
||||||
props.account.quota_limit !== null &&
|
|
||||||
props.account.quota_limit > 0
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// 当前已用配额
|
const dailyQuotaClass = computed(() =>
|
||||||
const currentQuotaUsed = computed(() => props.account.quota_used ?? 0)
|
quotaBadgeClass(props.account.quota_daily_used ?? 0, props.account.quota_daily_limit ?? 0)
|
||||||
|
)
|
||||||
|
|
||||||
// 配额状态样式
|
const dailyQuotaTooltip = computed(() =>
|
||||||
const quotaClass = computed(() => {
|
quotaBadgeTooltip(props.account.quota_daily_used ?? 0, props.account.quota_daily_limit ?? 0)
|
||||||
if (!showQuotaLimit.value) return ''
|
)
|
||||||
|
|
||||||
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) {
|
if (used >= limit) {
|
||||||
return 'bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400'
|
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-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'
|
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) {
|
if (used >= limit) {
|
||||||
return t('admin.accounts.capacity.quota.exceeded')
|
return t('admin.accounts.capacity.quota.exceeded')
|
||||||
}
|
}
|
||||||
return t('admin.accounts.capacity.quota.normal')
|
return t('admin.accounts.capacity.quota.normal')
|
||||||
})
|
}
|
||||||
|
|
||||||
// 格式化费用显示
|
// 格式化费用显示
|
||||||
const formatCost = (value: number | null | undefined) => {
|
const formatCost = (value: number | null | undefined) => {
|
||||||
|
|||||||
@@ -76,10 +76,10 @@ const isRateLimited = computed(() => {
|
|||||||
})
|
})
|
||||||
const isOverloaded = computed(() => props.account?.overload_until && new Date(props.account.overload_until) > new Date())
|
const isOverloaded = computed(() => props.account?.overload_until && new Date(props.account.overload_until) > new Date())
|
||||||
const hasQuotaLimit = computed(() => {
|
const hasQuotaLimit = computed(() => {
|
||||||
return props.account?.type === 'apikey' &&
|
if (props.account?.type !== 'apikey') return false
|
||||||
props.account?.quota_limit !== undefined &&
|
return (props.account?.quota_limit != null && props.account.quota_limit > 0) ||
|
||||||
props.account?.quota_limit !== null &&
|
(props.account?.quota_daily_limit != null && props.account.quota_daily_limit > 0) ||
|
||||||
props.account?.quota_limit > 0
|
(props.account?.quota_weekly_limit != null && props.account.quota_weekly_limit > 0)
|
||||||
})
|
})
|
||||||
|
|
||||||
const handleKeydown = (event: KeyboardEvent) => {
|
const handleKeydown = (event: KeyboardEvent) => {
|
||||||
|
|||||||
@@ -717,6 +717,10 @@ export interface Account {
|
|||||||
// API Key 账号配额限制
|
// API Key 账号配额限制
|
||||||
quota_limit?: number | null
|
quota_limit?: number | null
|
||||||
quota_used?: 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 // 当前窗口费用
|
current_window_cost?: number | null // 当前窗口费用
|
||||||
|
|||||||
Reference in new issue
Block a user