From e051ade27e5438d017f155b8c53a05cf693fcc16 Mon Sep 17 00:00:00 2001 From: AAEE86 Date: Tue, 14 Oct 2025 01:05:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8C=89=E6=9C=80=E6=96=B0=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E6=97=B6=E9=97=B4=E6=8E=92=E5=BA=8FAPI=20Keys?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../accounts/ApiKeyManagementModal.vue | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/web/admin-spa/src/components/accounts/ApiKeyManagementModal.vue b/web/admin-spa/src/components/accounts/ApiKeyManagementModal.vue index 1342b6af..da9970e0 100644 --- a/web/admin-spa/src/components/accounts/ApiKeyManagementModal.vue +++ b/web/admin-spa/src/components/accounts/ApiKeyManagementModal.vue @@ -261,7 +261,7 @@ const loadApiKeys = async () => { } // 转换为统一格式 - apiKeys.value = parsedKeys.map((item) => { + const formattedKeys = parsedKeys.map((item) => { if (typeof item === 'string') { // 对于字符串类型的API Key,保持默认状态为active return { @@ -290,6 +290,24 @@ const loadApiKeys = async () => { 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) { console.error('Failed to load API keys:', error) showToast('加载 API Key 失败', 'error')