fix(mining-admin-web): 修复用户列表API响应格式不匹配问题
- 添加transformUserOverview和transformUserDetail函数 - 转换后端返回格式(data/pagination)到前端期望格式(items) - 修复keyword到search的参数名转换 - 解决React hydration错误和数据不显示问题 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
3fe4f82906
commit
99550a2a9d
|
|
@ -11,15 +11,76 @@ import type {
|
||||||
} from '@/types/user';
|
} from '@/types/user';
|
||||||
import type { PaginatedResponse, PaginationParams } from '@/types/api';
|
import type { PaginatedResponse, PaginationParams } from '@/types/api';
|
||||||
|
|
||||||
|
// 转换后端用户数据到前端 UserOverview 格式
|
||||||
|
function transformUserOverview(backendUser: any): UserOverview {
|
||||||
|
return {
|
||||||
|
accountSequence: backendUser.accountSequence,
|
||||||
|
nickname: backendUser.realName || backendUser.nickname || '',
|
||||||
|
phone: backendUser.phone || '',
|
||||||
|
phoneNumberMasked: backendUser.phone,
|
||||||
|
avatar: null,
|
||||||
|
hasAdopted: backendUser.contribution?.hasAdopted || false,
|
||||||
|
totalContribution: backendUser.contribution?.totalContribution || '0',
|
||||||
|
effectiveContribution: backendUser.contribution?.effectiveContribution || '0',
|
||||||
|
miningBalance: backendUser.mining?.availableBalance || '0',
|
||||||
|
tradingBalance: backendUser.trading?.shareBalance || '0',
|
||||||
|
frozenBalance: '0',
|
||||||
|
personalAdoptions: 0,
|
||||||
|
teamAdoptions: 0,
|
||||||
|
referrerId: null,
|
||||||
|
status: backendUser.status?.toLowerCase() as 'active' | 'frozen' | 'deactivated',
|
||||||
|
isOnline: false,
|
||||||
|
createdAt: backendUser.createdAt,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// 转换后端用户详情到前端 UserDetail 格式
|
||||||
|
function transformUserDetail(backendUser: any): UserDetail {
|
||||||
|
return {
|
||||||
|
...transformUserOverview(backendUser),
|
||||||
|
referrerAccountSequence: null,
|
||||||
|
directReferralCount: backendUser.contribution?.directReferralCount || 0,
|
||||||
|
directReferralAdoptedCount: 0,
|
||||||
|
teamSize: 0,
|
||||||
|
teamAdoptedCount: 0,
|
||||||
|
contributions: {
|
||||||
|
personal: backendUser.contribution?.personalContribution || '0',
|
||||||
|
systemOperation: '0',
|
||||||
|
systemProvince: '0',
|
||||||
|
systemCity: '0',
|
||||||
|
teamLevel: backendUser.contribution?.teamLevelContribution || '0',
|
||||||
|
teamBonus: backendUser.contribution?.teamBonusContribution || '0',
|
||||||
|
total: backendUser.contribution?.totalContribution || '0',
|
||||||
|
},
|
||||||
|
kycStatus: backendUser.kycStatus,
|
||||||
|
registeredAt: backendUser.createdAt,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export const usersApi = {
|
export const usersApi = {
|
||||||
getList: async (params: PaginationParams & { keyword?: string }): Promise<PaginatedResponse<UserOverview>> => {
|
getList: async (params: PaginationParams & { keyword?: string }): Promise<PaginatedResponse<UserOverview>> => {
|
||||||
const response = await apiClient.get('/users', { params });
|
// 转换参数名: keyword -> search
|
||||||
return response.data.data;
|
const apiParams = {
|
||||||
|
page: params.page,
|
||||||
|
pageSize: params.pageSize,
|
||||||
|
search: params.keyword,
|
||||||
|
};
|
||||||
|
const response = await apiClient.get('/users', { params: apiParams });
|
||||||
|
// 后端返回格式: { data: [...], pagination: { page, pageSize, total, totalPages } }
|
||||||
|
// 前端期望格式: { items: [...], total, page, pageSize, totalPages }
|
||||||
|
const result = response.data.data;
|
||||||
|
return {
|
||||||
|
items: (result.data || []).map((user: any) => transformUserOverview(user)),
|
||||||
|
total: result.pagination?.total || 0,
|
||||||
|
page: result.pagination?.page || 1,
|
||||||
|
pageSize: result.pagination?.pageSize || 20,
|
||||||
|
totalPages: result.pagination?.totalPages || 0,
|
||||||
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
getDetail: async (accountSequence: string): Promise<UserDetail> => {
|
getDetail: async (accountSequence: string): Promise<UserDetail> => {
|
||||||
const response = await apiClient.get(`/users/${accountSequence}`);
|
const response = await apiClient.get(`/users/${accountSequence}`);
|
||||||
return response.data.data;
|
return transformUserDetail(response.data.data);
|
||||||
},
|
},
|
||||||
|
|
||||||
getContributionRecords: async (
|
getContributionRecords: async (
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue