From 7fd94ab78b6e19acb2ec8a5bda197a906729ee0c Mon Sep 17 00:00:00 2001 From: shaw Date: Fri, 19 Dec 2025 16:57:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dusage=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E6=9C=AA=E6=98=BE=E7=A4=BA=E7=BC=93=E5=AD=98=E5=86=99?= =?UTF-8?q?=E5=85=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/i18n/locales/en.ts | 2 + frontend/src/i18n/locales/zh.ts | 2 + frontend/src/views/admin/UsageView.vue | 56 +++++++++++++++++++++----- frontend/src/views/user/UsageView.vue | 56 +++++++++++++++++++++----- 4 files changed, 94 insertions(+), 22 deletions(-) diff --git a/frontend/src/i18n/locales/en.ts b/frontend/src/i18n/locales/en.ts index 16ff379e..b9420eab 100644 --- a/frontend/src/i18n/locales/en.ts +++ b/frontend/src/i18n/locales/en.ts @@ -266,6 +266,8 @@ export default { sync: 'Sync', in: 'In', out: 'Out', + cacheRead: 'Read', + cacheWrite: 'Write', rate: 'Rate', original: 'Original', billed: 'Billed', diff --git a/frontend/src/i18n/locales/zh.ts b/frontend/src/i18n/locales/zh.ts index f80b5c89..0e2e9ec5 100644 --- a/frontend/src/i18n/locales/zh.ts +++ b/frontend/src/i18n/locales/zh.ts @@ -266,6 +266,8 @@ export default { sync: '同步', in: '输入', out: '输出', + cacheRead: '读取', + cacheWrite: '写入', rate: '倍率', original: '原始', billed: '计费', diff --git a/frontend/src/views/admin/UsageView.vue b/frontend/src/views/admin/UsageView.vue index d0aec771..5c5a69c7 100644 --- a/frontend/src/views/admin/UsageView.vue +++ b/frontend/src/views/admin/UsageView.vue @@ -194,17 +194,40 @@ @@ -457,6 +480,16 @@ const formatTokens = (value: number): string => { return value.toLocaleString() } +// Compact format for cache tokens in table cells +const formatCacheTokens = (value: number): string => { + if (value >= 1_000_000) { + return `${(value / 1_000_000).toFixed(1)}M` + } else if (value >= 1_000) { + return `${(value / 1_000).toFixed(1)}K` + } + return value.toLocaleString() +} + const formatDateTime = (dateString: string): string => { const date = new Date(dateString) return date.toLocaleString('en-US', { @@ -537,7 +570,7 @@ const exportToCSV = () => { return } - const headers = ['User', 'API Key', 'Model', 'Type', 'Input Tokens', 'Output Tokens', 'Cache Tokens', 'Total Cost', 'Billing Type', 'Duration (ms)', 'Time'] + const headers = ['User', 'API Key', 'Model', 'Type', 'Input Tokens', 'Output Tokens', 'Cache Read Tokens', 'Cache Write Tokens', 'Total Cost', 'Billing Type', 'Duration (ms)', 'Time'] const rows = usageLogs.value.map(log => [ log.user?.email || '', log.api_key?.name || '', @@ -546,6 +579,7 @@ const exportToCSV = () => { log.input_tokens, log.output_tokens, log.cache_read_tokens, + log.cache_creation_tokens, log.total_cost.toFixed(6), log.billing_type === 1 ? 'Subscription' : 'Balance', log.duration_ms, diff --git a/frontend/src/views/user/UsageView.vue b/frontend/src/views/user/UsageView.vue index eda1f021..c8c40b9d 100644 --- a/frontend/src/views/user/UsageView.vue +++ b/frontend/src/views/user/UsageView.vue @@ -137,17 +137,40 @@ @@ -331,6 +354,16 @@ const formatTokens = (value: number): string => { return value.toLocaleString() } +// Compact format for cache tokens in table cells +const formatCacheTokens = (value: number): string => { + if (value >= 1_000_000) { + return `${(value / 1_000_000).toFixed(1)}M` + } else if (value >= 1_000) { + return `${(value / 1_000).toFixed(1)}K` + } + return value.toLocaleString() +} + const formatDateTime = (dateString: string): string => { const date = new Date(dateString) return date.toLocaleString('en-US', { @@ -415,13 +448,14 @@ const exportToCSV = () => { return } - const headers = ['Model', 'Type', 'Input Tokens', 'Output Tokens', 'Cache Tokens', 'Total Cost', 'Billing Type', 'First Token (ms)', 'Duration (ms)', 'Time'] + const headers = ['Model', 'Type', 'Input Tokens', 'Output Tokens', 'Cache Read Tokens', 'Cache Write Tokens', 'Total Cost', 'Billing Type', 'First Token (ms)', 'Duration (ms)', 'Time'] const rows = usageLogs.value.map(log => [ log.model, log.stream ? 'Stream' : 'Sync', log.input_tokens, log.output_tokens, log.cache_read_tokens, + log.cache_creation_tokens, log.total_cost.toFixed(6), log.billing_type === 1 ? 'Subscription' : 'Balance', log.first_token_ms ?? '',