diff --git a/web/admin-spa/src/views/ApiKeysView.vue b/web/admin-spa/src/views/ApiKeysView.vue index 20e48a7a..d06cff76 100644 --- a/web/admin-spa/src/views/ApiKeysView.vue +++ b/web/admin-spa/src/views/ApiKeysView.vue @@ -244,22 +244,39 @@ - 使用统计 - - (费用 - - ) - +
+ 使用统计 + + 今日费用 + + + + + 总费用 + + + +
${{ (key.dailyCost || 0).toFixed(4) }} +
+ 总费用 + ${{ (key.totalCost || 0).toFixed(4) }} +
最后使用 {{ @@ -1590,8 +1613,8 @@ const apiKeyStatsTimeRange = ref('today') const activeTab = ref('active') const deletedApiKeys = ref([]) const deletedApiKeysLoading = ref(false) -const apiKeysSortBy = ref('') -const apiKeysSortOrder = ref('asc') +const apiKeysSortBy = ref('dailyCost') +const apiKeysSortOrder = ref('desc') const expandedApiKeys = ref({}) const apiKeyModelStats = ref({}) const apiKeyDateFilters = ref({}) @@ -1696,9 +1719,12 @@ const sortedApiKeys = computed(() => { if (apiKeysSortBy.value === 'status') { aVal = a.isActive ? 1 : 0 bVal = b.isActive ? 1 : 0 - } else if (apiKeysSortBy.value === 'cost') { - aVal = parseFloat(calculateApiKeyCost(a.usage).replace('$', '')) - bVal = parseFloat(calculateApiKeyCost(b.usage).replace('$', '')) + } else if (apiKeysSortBy.value === 'dailyCost') { + aVal = a.dailyCost || 0 + bVal = b.dailyCost || 0 + } else if (apiKeysSortBy.value === 'totalCost') { + aVal = a.totalCost || 0 + bVal = b.totalCost || 0 } else if (apiKeysSortBy.value === 'createdAt' || apiKeysSortBy.value === 'expiresAt') { aVal = aVal ? new Date(aVal).getTime() : 0 bVal = bVal ? new Date(bVal).getTime() : 0 @@ -1883,13 +1909,6 @@ const formatNumber = (num) => { return num.toLocaleString('zh-CN') } -// 计算API Key费用 -const calculateApiKeyCost = (usage) => { - if (!usage || !usage.total) return '$0.0000' - const cost = usage.total.cost || 0 - return `$${cost.toFixed(4)}` -} - // 获取绑定账户名称 const getBoundAccountName = (accountId) => { if (!accountId) return '未知账户'