diff --git a/src/routes/admin.js b/src/routes/admin.js index 954d2f98..5308b0e8 100644 --- a/src/routes/admin.js +++ b/src/routes/admin.js @@ -30,18 +30,19 @@ const router = express.Router() router.get('/users', authenticateAdmin, async (req, res) => { try { const userService = require('../services/userService') - const allUsers = await userService.getAllUsers() + const result = await userService.getAllUsers({ isActive: true, limit: 1000 }) // Get all active users - // 只返回活跃用户,并包含管理员选项 - const activeUsers = allUsers - .filter((user) => user.isActive) - .map((user) => ({ - id: user.id, - username: user.username, - displayName: user.displayName || user.username, - email: user.email, - role: user.role - })) + // Extract users array from the paginated result + const allUsers = result.users || [] + + // Map to the format needed for the dropdown + const activeUsers = allUsers.map((user) => ({ + id: user.id, + username: user.username, + displayName: user.displayName || user.username, + email: user.email, + role: user.role + })) // 添加Admin选项作为第一个 const usersWithAdmin = [ diff --git a/web/admin-spa/src/components/apikeys/EditApiKeyModal.vue b/web/admin-spa/src/components/apikeys/EditApiKeyModal.vue index 82e27447..1484f41a 100644 --- a/web/admin-spa/src/components/apikeys/EditApiKeyModal.vue +++ b/web/admin-spa/src/components/apikeys/EditApiKeyModal.vue @@ -999,11 +999,22 @@ const loadUsers = async () => { // 初始化表单数据 onMounted(async () => { - // 并行加载所有需要的数据 - await Promise.all([clientsStore.loadSupportedClients(), apiKeysStore.fetchTags(), loadUsers()]) + try { + // 并行加载所有需要的数据 + const [clients, tags] = await Promise.all([ + clientsStore.loadSupportedClients(), + apiKeysStore.fetchTags(), + loadUsers() + ]) - supportedClients.value = clientsStore.supportedClients - availableTags.value = apiKeysStore.availableTags + supportedClients.value = clients || [] + availableTags.value = tags || [] + } catch (error) { + console.error('Error loading initial data:', error) + // Fallback to empty arrays if loading fails + supportedClients.value = [] + availableTags.value = [] + } // 初始化账号数据 if (props.accounts) {