feat: Add useS2AApi hook for interacting with S2A dashboard statistics and account management.

This commit is contained in:
2026-01-30 19:07:40 +08:00
parent 6f18740215
commit 364b393bc6

View File

@@ -41,12 +41,34 @@ export function useS2AApi() {
try {
const response: AccountListResponse = await s2aClient.getAccounts(params)
console.log('S2A getAccounts response:', response)
// 兼容不同的响应格式
// 格式1: { data: [...], total: N }
// 格式2: { list: [...], total: N }
// 格式3: 直接是数组 [...]
let accounts: S2AAccount[] = []
let total = 0
if (Array.isArray(response)) {
accounts = response as unknown as S2AAccount[]
total = accounts.length
} else if (response.data && Array.isArray(response.data)) {
accounts = response.data
total = response.total || accounts.length
} else if ((response as unknown as { list: S2AAccount[] }).list) {
accounts = (response as unknown as { list: S2AAccount[] }).list
total = response.total || accounts.length
}
console.log('Parsed accounts:', accounts.length, 'total:', total)
return {
data: response.data || [],
total: response.total || 0,
data: accounts,
total: total,
page: response.page || 1,
page_size: response.page_size || 20,
total_pages: Math.ceil((response.total || 0) / (response.page_size || 20)),
total_pages: Math.ceil(total / (response.page_size || 20)),
}
} catch (err) {
const message = err instanceof Error ? err.message : '获取账号列表失败'