From 96094cfde215093a0234ce2f7b3f2d8f7a380fba Mon Sep 17 00:00:00 2001 From: fawney19 Date: Mon, 29 Dec 2025 18:28:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B0=83=E6=95=B4=E4=BB=AA=E8=A1=A8?= =?UTF-8?q?=E7=9B=98=E6=99=AE=E9=80=9A=E7=94=A8=E6=88=B7=E6=9C=88=E5=BA=A6?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E6=98=BE=E7=A4=BA=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=9C=88=E5=BA=A6=E8=B4=B9=E7=94=A8=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/api/dashboard.ts | 2 ++ frontend/src/views/shared/Dashboard.vue | 46 +++++++++++++++++-------- src/api/dashboard/routes.py | 14 ++++++-- 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/frontend/src/api/dashboard.ts b/frontend/src/api/dashboard.ts index f4f3ed7..bcc00b9 100644 --- a/frontend/src/api/dashboard.ts +++ b/frontend/src/api/dashboard.ts @@ -87,6 +87,8 @@ export interface DashboardStatsResponse { cache_stats?: CacheStats users?: UserStats token_breakdown?: TokenBreakdown + // 普通用户专用字段 + monthly_cost?: number } export interface RecentRequestsResponse { diff --git a/frontend/src/views/shared/Dashboard.vue b/frontend/src/views/shared/Dashboard.vue index 9449872..b1eee04 100644 --- a/frontend/src/views/shared/Dashboard.vue +++ b/frontend/src/views/shared/Dashboard.vue @@ -162,14 +162,14 @@ - +

- 本月缓存使用 + 本月统计

-
- +
+

@@ -190,7 +198,10 @@

- +

@@ -201,7 +212,10 @@

- +

@@ -213,19 +227,16 @@

- +

- 总Token + 本月费用

- {{ formatTokens((tokenBreakdown.input || 0) + (tokenBreakdown.output || 0)) }} -

-

- 输入 {{ formatTokens(tokenBreakdown.input || 0) }} / 输出 {{ formatTokens(tokenBreakdown.output || 0) }} + {{ formatCurrency(userMonthlyCost) }}

@@ -831,6 +842,12 @@ const cacheStats = ref<{ total_cache_tokens: number } | null>(null) +const userMonthlyCost = ref(null) + +const hasCacheData = computed(() => + cacheStats.value && cacheStats.value.total_cache_tokens > 0 +) + const tokenBreakdown = ref<{ input: number output: number @@ -1086,6 +1103,7 @@ async function loadDashboardData() { } else { if (statsData.cache_stats) cacheStats.value = statsData.cache_stats if (statsData.token_breakdown) tokenBreakdown.value = statsData.token_breakdown + if (statsData.monthly_cost !== undefined) userMonthlyCost.value = statsData.monthly_cost } } finally { loading.value = false diff --git a/src/api/dashboard/routes.py b/src/api/dashboard/routes.py index 006cb1d..e091c0a 100644 --- a/src/api/dashboard/routes.py +++ b/src/api/dashboard/routes.py @@ -610,9 +610,15 @@ class UserDashboardStatsAdapter(DashboardAdapter): "icon": "TrendingUp", }, { - "name": "本月费用", - "value": f"${user_cost:.2f}", - "icon": "DollarSign", + "name": "总Token", + "value": format_tokens( + 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": { @@ -636,6 +642,8 @@ class UserDashboardStatsAdapter(DashboardAdapter): "cache_hit_rate": cache_hit_rate, "total_cache_tokens": cache_creation_tokens + cache_read_tokens, }, + # 本月费用(用于下方缓存区域显示) + "monthly_cost": float(user_cost), }