feat: 增强 API Key 标签选择功能

- 添加获取已存在标签的 API 端点 /admin/api-keys/tags
- 重构标签输入 UI,从下拉菜单改为平铺展示
- 支持点击选择已有标签,避免重复创建
- 增加弹框宽度 (max-w-4xl),改善布局和用户体验
- 统一创建和编辑 API Key 的标签管理体验

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Alfonsxh
2025-07-30 11:24:27 +08:00
parent dae8e8e914
commit fc5c24e1ca
4 changed files with 230 additions and 111 deletions

View File

@@ -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 {