mirror of
https://github.com/fawney19/Aether.git
synced 2026-01-02 15:52:26 +08:00
fix: 调整仪表盘普通用户月度统计显示,添加月度费用字段
This commit is contained in:
@@ -87,6 +87,8 @@ export interface DashboardStatsResponse {
|
|||||||
cache_stats?: CacheStats
|
cache_stats?: CacheStats
|
||||||
users?: UserStats
|
users?: UserStats
|
||||||
token_breakdown?: TokenBreakdown
|
token_breakdown?: TokenBreakdown
|
||||||
|
// 普通用户专用字段
|
||||||
|
monthly_cost?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RecentRequestsResponse {
|
export interface RecentRequestsResponse {
|
||||||
|
|||||||
@@ -162,14 +162,14 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 普通用户:缓存统计 -->
|
<!-- 普通用户:月度统计 -->
|
||||||
<div
|
<div
|
||||||
v-else-if="!isAdmin && cacheStats && cacheStats.total_cache_tokens > 0"
|
v-else-if="!isAdmin && (hasCacheData || (userMonthlyCost !== null && userMonthlyCost > 0))"
|
||||||
class="mt-6"
|
class="mt-6"
|
||||||
>
|
>
|
||||||
<div class="mb-3 flex items-center justify-between">
|
<div class="mb-3 flex items-center justify-between">
|
||||||
<h3 class="text-sm font-medium text-foreground">
|
<h3 class="text-sm font-medium text-foreground">
|
||||||
本月缓存使用
|
本月统计
|
||||||
</h3>
|
</h3>
|
||||||
<Badge
|
<Badge
|
||||||
variant="outline"
|
variant="outline"
|
||||||
@@ -178,8 +178,16 @@
|
|||||||
Monthly
|
Monthly
|
||||||
</Badge>
|
</Badge>
|
||||||
</div>
|
</div>
|
||||||
<div class="grid grid-cols-2 gap-2 sm:gap-3 xl:grid-cols-4">
|
<div
|
||||||
<Card class="relative p-3 sm:p-4 border-book-cloth/30">
|
:class="[
|
||||||
|
'grid gap-2 sm:gap-3',
|
||||||
|
hasCacheData ? 'grid-cols-2 xl:grid-cols-4' : 'grid-cols-1 max-w-xs'
|
||||||
|
]"
|
||||||
|
>
|
||||||
|
<Card
|
||||||
|
v-if="cacheStats"
|
||||||
|
class="relative p-3 sm:p-4 border-book-cloth/30"
|
||||||
|
>
|
||||||
<Database class="absolute top-3 right-3 h-3.5 w-3.5 sm:h-4 sm:w-4 text-muted-foreground" />
|
<Database class="absolute top-3 right-3 h-3.5 w-3.5 sm:h-4 sm:w-4 text-muted-foreground" />
|
||||||
<div class="pr-6">
|
<div class="pr-6">
|
||||||
<p class="text-[9px] sm:text-[10px] font-semibold uppercase tracking-[0.2em] sm:tracking-[0.3em] text-muted-foreground">
|
<p class="text-[9px] sm:text-[10px] font-semibold uppercase tracking-[0.2em] sm:tracking-[0.3em] text-muted-foreground">
|
||||||
@@ -190,7 +198,10 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
<Card class="relative p-3 sm:p-4 border-kraft/30">
|
<Card
|
||||||
|
v-if="cacheStats"
|
||||||
|
class="relative p-3 sm:p-4 border-kraft/30"
|
||||||
|
>
|
||||||
<Hash class="absolute top-3 right-3 h-3.5 w-3.5 sm:h-4 sm:w-4 text-muted-foreground" />
|
<Hash class="absolute top-3 right-3 h-3.5 w-3.5 sm:h-4 sm:w-4 text-muted-foreground" />
|
||||||
<div class="pr-6">
|
<div class="pr-6">
|
||||||
<p class="text-[9px] sm:text-[10px] font-semibold uppercase tracking-[0.2em] sm:tracking-[0.3em] text-muted-foreground">
|
<p class="text-[9px] sm:text-[10px] font-semibold uppercase tracking-[0.2em] sm:tracking-[0.3em] text-muted-foreground">
|
||||||
@@ -201,7 +212,10 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
<Card class="relative p-3 sm:p-4 border-book-cloth/25">
|
<Card
|
||||||
|
v-if="cacheStats"
|
||||||
|
class="relative p-3 sm:p-4 border-book-cloth/25"
|
||||||
|
>
|
||||||
<Database class="absolute top-3 right-3 h-3.5 w-3.5 sm:h-4 sm:w-4 text-muted-foreground" />
|
<Database class="absolute top-3 right-3 h-3.5 w-3.5 sm:h-4 sm:w-4 text-muted-foreground" />
|
||||||
<div class="pr-6">
|
<div class="pr-6">
|
||||||
<p class="text-[9px] sm:text-[10px] font-semibold uppercase tracking-[0.2em] sm:tracking-[0.3em] text-muted-foreground">
|
<p class="text-[9px] sm:text-[10px] font-semibold uppercase tracking-[0.2em] sm:tracking-[0.3em] text-muted-foreground">
|
||||||
@@ -213,19 +227,16 @@
|
|||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
<Card
|
<Card
|
||||||
v-if="tokenBreakdown"
|
v-if="userMonthlyCost !== null"
|
||||||
class="relative p-3 sm:p-4 border-manilla/40"
|
class="relative p-3 sm:p-4 border-manilla/40"
|
||||||
>
|
>
|
||||||
<Hash class="absolute top-3 right-3 h-3.5 w-3.5 sm:h-4 sm:w-4 text-muted-foreground" />
|
<DollarSign class="absolute top-3 right-3 h-3.5 w-3.5 sm:h-4 sm:w-4 text-muted-foreground" />
|
||||||
<div class="pr-6">
|
<div class="pr-6">
|
||||||
<p class="text-[9px] sm:text-[10px] font-semibold uppercase tracking-[0.2em] sm:tracking-[0.3em] text-muted-foreground">
|
<p class="text-[9px] sm:text-[10px] font-semibold uppercase tracking-[0.2em] sm:tracking-[0.3em] text-muted-foreground">
|
||||||
总Token
|
本月费用
|
||||||
</p>
|
</p>
|
||||||
<p class="mt-1.5 sm:mt-2 text-lg sm:text-xl font-semibold text-foreground">
|
<p class="mt-1.5 sm:mt-2 text-lg sm:text-xl font-semibold text-foreground">
|
||||||
{{ formatTokens((tokenBreakdown.input || 0) + (tokenBreakdown.output || 0)) }}
|
{{ formatCurrency(userMonthlyCost) }}
|
||||||
</p>
|
|
||||||
<p class="mt-0.5 sm:mt-1 text-[9px] sm:text-[10px] text-muted-foreground">
|
|
||||||
输入 {{ formatTokens(tokenBreakdown.input || 0) }} / 输出 {{ formatTokens(tokenBreakdown.output || 0) }}
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
@@ -831,6 +842,12 @@ const cacheStats = ref<{
|
|||||||
total_cache_tokens: number
|
total_cache_tokens: number
|
||||||
} | null>(null)
|
} | null>(null)
|
||||||
|
|
||||||
|
const userMonthlyCost = ref<number | null>(null)
|
||||||
|
|
||||||
|
const hasCacheData = computed(() =>
|
||||||
|
cacheStats.value && cacheStats.value.total_cache_tokens > 0
|
||||||
|
)
|
||||||
|
|
||||||
const tokenBreakdown = ref<{
|
const tokenBreakdown = ref<{
|
||||||
input: number
|
input: number
|
||||||
output: number
|
output: number
|
||||||
@@ -1086,6 +1103,7 @@ async function loadDashboardData() {
|
|||||||
} else {
|
} else {
|
||||||
if (statsData.cache_stats) cacheStats.value = statsData.cache_stats
|
if (statsData.cache_stats) cacheStats.value = statsData.cache_stats
|
||||||
if (statsData.token_breakdown) tokenBreakdown.value = statsData.token_breakdown
|
if (statsData.token_breakdown) tokenBreakdown.value = statsData.token_breakdown
|
||||||
|
if (statsData.monthly_cost !== undefined) userMonthlyCost.value = statsData.monthly_cost
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
|
|||||||
@@ -610,9 +610,15 @@ class UserDashboardStatsAdapter(DashboardAdapter):
|
|||||||
"icon": "TrendingUp",
|
"icon": "TrendingUp",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "本月费用",
|
"name": "总Token",
|
||||||
"value": f"${user_cost:.2f}",
|
"value": format_tokens(
|
||||||
"icon": "DollarSign",
|
all_time_input_tokens
|
||||||
|
+ all_time_output_tokens
|
||||||
|
+ all_time_cache_creation
|
||||||
|
+ all_time_cache_read
|
||||||
|
),
|
||||||
|
"subValue": f"输入 {format_tokens(all_time_input_tokens)} / 输出 {format_tokens(all_time_output_tokens)}",
|
||||||
|
"icon": "Hash",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"today": {
|
"today": {
|
||||||
@@ -636,6 +642,8 @@ class UserDashboardStatsAdapter(DashboardAdapter):
|
|||||||
"cache_hit_rate": cache_hit_rate,
|
"cache_hit_rate": cache_hit_rate,
|
||||||
"total_cache_tokens": cache_creation_tokens + cache_read_tokens,
|
"total_cache_tokens": cache_creation_tokens + cache_read_tokens,
|
||||||
},
|
},
|
||||||
|
# 本月费用(用于下方缓存区域显示)
|
||||||
|
"monthly_cost": float(user_cost),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user