diff --git a/backend/internal/setup/setup.go b/backend/internal/setup/setup.go index 4b1ca7b2..65118161 100644 --- a/backend/internal/setup/setup.go +++ b/backend/internal/setup/setup.go @@ -39,8 +39,8 @@ func GetDataDir() string { // Try to check if writable by creating a temp file testFile := dockerDataDir + "/.write_test" if f, err := os.Create(testFile); err == nil { - f.Close() - os.Remove(testFile) + _ = f.Close() + _ = os.Remove(testFile) return dockerDataDir } } diff --git a/frontend/src/components/user/dashboard/UserDashboardStats.vue b/frontend/src/components/user/dashboard/UserDashboardStats.vue index d375ba88..dfba3a51 100644 --- a/frontend/src/components/user/dashboard/UserDashboardStats.vue +++ b/frontend/src/components/user/dashboard/UserDashboardStats.vue @@ -153,6 +153,10 @@ const formatBalance = (b: number) => const formatNumber = (n: number) => n.toLocaleString() const formatCost = (c: number) => c.toFixed(4) -const formatTokens = (t: number) => (t >= 1000 ? `${(t / 1000).toFixed(1)}K` : t.toString()) +const formatTokens = (t: number) => { + if (t >= 1_000_000) return `${(t / 1_000_000).toFixed(1)}M` + if (t >= 1000) return `${(t / 1000).toFixed(1)}K` + return t.toString() +} const formatDuration = (ms: number) => ms >= 1000 ? `${(ms / 1000).toFixed(2)}s` : `${ms.toFixed(0)}ms` diff --git a/frontend/src/utils/format.ts b/frontend/src/utils/format.ts index d54e5015..2dc8da4e 100644 --- a/frontend/src/utils/format.ts +++ b/frontend/src/utils/format.ts @@ -174,10 +174,12 @@ export function formatCostFixed(amount: number, fractionDigits: number = 4): str } /** - * 格式化 token 数量(>=1000 显示为 K,保留 1 位小数) + * 格式化 token 数量(>=1M 显示为 M,>=1K 显示为 K,保留 1 位小数) * @param tokens token 数量 - * @returns 格式化后的字符串,如 "950", "1.2K" + * @returns 格式化后的字符串,如 "950", "1.2K", "3.5M" */ export function formatTokensK(tokens: number): string { - return tokens >= 1000 ? `${(tokens / 1000).toFixed(1)}K` : tokens.toString() + if (tokens >= 1_000_000) return `${(tokens / 1_000_000).toFixed(1)}M` + if (tokens >= 1000) return `${(tokens / 1000).toFixed(1)}K` + return tokens.toString() }