refactor(ui): extract formatCacheTokens and formatMultiplier to shared utils
This commit is contained in:
@@ -326,6 +326,7 @@
|
||||
import { ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { formatDateTime, formatReasoningEffort } from '@/utils/format'
|
||||
import { formatCacheTokens, formatMultiplier } from '@/utils/formatters'
|
||||
import { formatTokenPricePerMillion } from '@/utils/usagePricing'
|
||||
import { getUsageServiceTierLabel } from '@/utils/usageServiceTier'
|
||||
import { resolveUsageRequestType } from '@/utils/usageRequestType'
|
||||
@@ -376,19 +377,6 @@ const getBillingModeBadgeClass = (mode: string | null | undefined): string => {
|
||||
return 'bg-gray-100 text-gray-800 dark:bg-gray-700 dark:text-gray-200'
|
||||
}
|
||||
|
||||
const formatCacheTokens = (tokens: number): string => {
|
||||
if (tokens >= 1000000) return `${(tokens / 1000000).toFixed(1)}M`
|
||||
if (tokens >= 1000) return `${(tokens / 1000).toFixed(1)}K`
|
||||
return tokens.toString()
|
||||
}
|
||||
|
||||
// 自适应精度:保留足够位数显示有效数字(如 0.001 → "0.001",1.5 → "1.50")
|
||||
const formatMultiplier = (val: number): string => {
|
||||
if (val >= 0.01) return val.toFixed(2)
|
||||
if (val >= 0.001) return val.toFixed(3)
|
||||
if (val >= 0.0001) return val.toFixed(4)
|
||||
return val.toPrecision(2)
|
||||
}
|
||||
|
||||
const formatUserAgent = (ua: string): string => {
|
||||
return ua
|
||||
|
||||
Reference in New Issue
Block a user