mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-22 16:43:35 +00:00
feat: 按最新使用时间排序API Keys
This commit is contained in:
@@ -261,7 +261,7 @@ const loadApiKeys = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 转换为统一格式
|
// 转换为统一格式
|
||||||
apiKeys.value = parsedKeys.map((item) => {
|
const formattedKeys = parsedKeys.map((item) => {
|
||||||
if (typeof item === 'string') {
|
if (typeof item === 'string') {
|
||||||
// 对于字符串类型的API Key,保持默认状态为active
|
// 对于字符串类型的API Key,保持默认状态为active
|
||||||
return {
|
return {
|
||||||
@@ -290,6 +290,24 @@ const loadApiKeys = async () => {
|
|||||||
errorMessage: ''
|
errorMessage: ''
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 按最新使用时间排序(最近使用的在前,未使用的在后)
|
||||||
|
apiKeys.value = formattedKeys.sort((a, b) => {
|
||||||
|
// 如果都有 lastUsedAt,按时间降序排序
|
||||||
|
if (a.lastUsedAt && b.lastUsedAt) {
|
||||||
|
return new Date(b.lastUsedAt) - new Date(a.lastUsedAt)
|
||||||
|
}
|
||||||
|
// 如果 a 有时间,b 没有,a 排在前面
|
||||||
|
if (a.lastUsedAt && !b.lastUsedAt) {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
// 如果 b 有时间,a 没有,b 排在前面
|
||||||
|
if (!a.lastUsedAt && b.lastUsedAt) {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
// 如果都没有时间,按使用次数降序排序
|
||||||
|
return (b.usageCount || 0) - (a.usageCount || 0)
|
||||||
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to load API keys:', error)
|
console.error('Failed to load API keys:', error)
|
||||||
showToast('加载 API Key 失败', 'error')
|
showToast('加载 API Key 失败', 'error')
|
||||||
|
|||||||
Reference in New Issue
Block a user