Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
6c718578
Commit
6c718578
authored
Apr 02, 2026
by
erio
Browse files
refactor(ui): extract formatCacheTokens and formatMultiplier to shared utils
parent
0d241d52
Changes
3
Hide whitespace changes
Inline
Side-by-side
frontend/src/components/admin/usage/UsageTable.vue
View file @
6c718578
...
...
@@ -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
...
...
frontend/src/utils/formatters.ts
0 → 100644
View file @
6c718578
/**
* 格式化缓存 token 数量(1K/1M 缩写)
*/
export
function
formatCacheTokens
(
tokens
:
number
):
string
{
if
(
tokens
>=
1000000
)
return
`
${(
tokens
/
1000000
).
toFixed
(
1
)}
M`
if
(
tokens
>=
1000
)
return
`
${(
tokens
/
1000
).
toFixed
(
1
)}
K`
return
tokens
.
toLocaleString
()
}
/**
* 自适应精度格式化倍率(确保小数值如 0.001 不被截断)
*/
export
function
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
)
}
frontend/src/views/user/UsageView.vue
View file @
6c718578
...
...
@@ -504,6 +504,7 @@ import type { UsageLog, ApiKey, UsageQueryParams, UsageStatsResponse } from '@/t
import
type
{
Column
}
from
'
@/components/common/types
'
import
{
formatDateTime
,
formatReasoningEffort
}
from
'
@/utils/format
'
import
{
getPersistedPageSize
}
from
'
@/composables/usePersistedPageSize
'
import
{
formatCacheTokens
,
formatMultiplier
}
from
'
@/utils/formatters
'
import
{
formatTokenPricePerMillion
}
from
'
@/utils/usagePricing
'
import
{
getUsageServiceTierLabel
}
from
'
@/utils/usageServiceTier
'
import
{
resolveUsageRequestType
}
from
'
@/utils/usageRequestType
'
...
...
@@ -659,22 +660,6 @@ 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
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
loadUsageLogs
=
async
()
=>
{
if
(
abortController
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment