From fc5c24e1ca46d562522e28ccc6163327ea3b7eca Mon Sep 17 00:00:00 2001 From: Alfonsxh Date: Wed, 30 Jul 2025 11:24:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=BC=BA=20API=20Key=20?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E9=80=89=E6=8B=A9=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加获取已存在标签的 API 端点 /admin/api-keys/tags - 重构标签输入 UI,从下拉菜单改为平铺展示 - 支持点击选择已有标签,避免重复创建 - 增加弹框宽度 (max-w-4xl),改善布局和用户体验 - 统一创建和编辑 API Key 的标签管理体验 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/routes/admin.js | 28 +++ .../components/apikeys/CreateApiKeyModal.vue | 97 ++++++--- .../components/apikeys/EditApiKeyModal.vue | 200 +++++++++++------- web/admin-spa/src/stores/apiKeys.js | 16 ++ 4 files changed, 230 insertions(+), 111 deletions(-) diff --git a/src/routes/admin.js b/src/routes/admin.js index 45330aa8..ebd58f72 100644 --- a/src/routes/admin.js +++ b/src/routes/admin.js @@ -303,6 +303,34 @@ router.get('/supported-clients', authenticateAdmin, async (req, res) => { } }); +// 获取已存在的标签列表 +router.get('/api-keys/tags', authenticateAdmin, async (req, res) => { + try { + const apiKeys = await apiKeyService.getAllApiKeys(); + const tagSet = new Set(); + + // 收集所有API Keys的标签 + for (const apiKey of apiKeys) { + if (apiKey.tags && Array.isArray(apiKey.tags)) { + apiKey.tags.forEach(tag => { + if (tag && tag.trim()) { + tagSet.add(tag.trim()); + } + }); + } + } + + // 转换为数组并排序 + const tags = Array.from(tagSet).sort(); + + logger.info(`📋 Retrieved ${tags.length} unique tags from API keys`); + res.json({ success: true, data: tags }); + } catch (error) { + logger.error('❌ Failed to get API key tags:', error); + res.status(500).json({ error: 'Failed to get API key tags', message: error.message }); + } +}); + // 创建新的API Key router.post('/api-keys', authenticateAdmin, async (req, res) => { try { diff --git a/web/admin-spa/src/components/apikeys/CreateApiKeyModal.vue b/web/admin-spa/src/components/apikeys/CreateApiKeyModal.vue index d643b173..50f76997 100644 --- a/web/admin-spa/src/components/apikeys/CreateApiKeyModal.vue +++ b/web/admin-spa/src/components/apikeys/CreateApiKeyModal.vue @@ -1,7 +1,7 @@