feat(users): add batch API store methods

This commit is contained in:
RWDai
2026-05-07 19:16:49 +08:00
parent 8fa90e8ecf
commit ea014e0d89
2 changed files with 104 additions and 3 deletions

View File

@@ -8,6 +8,10 @@ import {
type ApiKey,
type UpsertUserApiKeyRequest,
type UserSession,
type UserBatchSelection,
type ResolveUserBatchSelectionResponse,
type UserBatchActionRequest,
type UserBatchActionResponse,
} from '@/api/users'
import { parseApiError } from '@/utils/errorParser'
@@ -83,6 +87,30 @@ export const useUsersStore = defineStore('users', () => {
}
}
async function resolveBatchSelection(
selection: UserBatchSelection
): Promise<ResolveUserBatchSelectionResponse> {
try {
return await usersApi.resolveBatchSelection(selection)
} catch (err: unknown) {
error.value = parseApiError(err, '解析用户选择失败')
throw err
}
}
async function batchAction(request: UserBatchActionRequest): Promise<UserBatchActionResponse> {
loading.value = true
error.value = null
try {
return await usersApi.batchAction(request)
} catch (err: unknown) {
error.value = parseApiError(err, '批量操作用户失败')
throw err
} finally {
loading.value = false
}
}
async function getUserApiKeys(userId: string): Promise<ApiKey[]> {
try {
return await usersApi.getUserApiKeys(userId)
@@ -169,6 +197,8 @@ export const useUsersStore = defineStore('users', () => {
createUser,
updateUser,
deleteUser,
resolveBatchSelection,
batchAction,
getUserApiKeys,
createApiKey,
updateApiKey,