|
|
@@ -108,10 +108,17 @@ export const UserConsumptionTable: React.FC<UserConsumptionTableProps> = ({
|
|
|
onPermissionCheck
|
|
|
}) => {
|
|
|
const [pagination, setPagination] = useState<PaginationParams>(initialPagination);
|
|
|
+ const [forceRefresh, setForceRefresh] = useState(false);
|
|
|
|
|
|
// 构建查询参数
|
|
|
const buildQueryParams = useCallback(() => {
|
|
|
- const params: Record<string, string | number> = {};
|
|
|
+ const params: Record<string, string | number> & {
|
|
|
+ page: number;
|
|
|
+ limit: number;
|
|
|
+ } = {
|
|
|
+ page: 1,
|
|
|
+ limit: 10
|
|
|
+ };
|
|
|
|
|
|
// 分页参数 - 确保传递数字类型
|
|
|
if (pagination.page !== undefined) {
|
|
|
@@ -146,19 +153,13 @@ export const UserConsumptionTable: React.FC<UserConsumptionTableProps> = ({
|
|
|
params.year = Number(timeFilter.year); // 确保传递数字
|
|
|
}
|
|
|
|
|
|
- // 确保有默认值(数字类型)
|
|
|
- if (!params.page) params.page = 1;
|
|
|
- if (!params.limit) params.limit = 10;
|
|
|
-
|
|
|
- // 调试:记录参数类型
|
|
|
- console.debug('用户消费统计API调试 - 参数类型检查:', {
|
|
|
- page: { value: params.page, type: typeof params.page },
|
|
|
- limit: { value: params.limit, type: typeof params.limit },
|
|
|
- year: { value: params.year, type: typeof params.year }
|
|
|
- });
|
|
|
+ // 添加强制刷新参数
|
|
|
+ if (forceRefresh) {
|
|
|
+ params.forceRefresh = true;
|
|
|
+ }
|
|
|
|
|
|
return params;
|
|
|
- }, [pagination, timeFilter]);
|
|
|
+ }, [pagination, timeFilter, forceRefresh]);
|
|
|
|
|
|
// 用户消费统计查询
|
|
|
const {
|
|
|
@@ -167,33 +168,22 @@ export const UserConsumptionTable: React.FC<UserConsumptionTableProps> = ({
|
|
|
error: consumptionError,
|
|
|
refetch: refetchConsumption
|
|
|
} = useQuery({
|
|
|
- queryKey: ['data-overview-user-consumption', tenantId, timeFilter, pagination],
|
|
|
+ queryKey: ['data-overview-user-consumption', tenantId, timeFilter, pagination, forceRefresh],
|
|
|
queryFn: async () => {
|
|
|
let res;
|
|
|
try {
|
|
|
const queryParams = buildQueryParams();
|
|
|
- console.debug('用户消费统计API调试 - 完整请求URL:', '/api/v1/data-overview/user-consumption');
|
|
|
- console.debug('用户消费统计API调试 - 查询参数:', queryParams);
|
|
|
- console.debug('用户消费统计API调试 - 客户端管理器:', dataOverviewClientManager);
|
|
|
+ console.debug('用户消费统计API请求:', { timeRange: timeFilter.timeRange, forceRefresh, pagination });
|
|
|
res = await dataOverviewClientManager.get()['user-consumption'].$get({
|
|
|
query: queryParams
|
|
|
});
|
|
|
|
|
|
- console.debug('用户消费统计API调试 - 响应状态:', res.status);
|
|
|
- console.debug('用户消费统计API调试 - 响应Headers:', Object.fromEntries(res.headers.entries()));
|
|
|
-
|
|
|
- // 先读取原始响应文本,以便调试
|
|
|
- console.debug('用户消费统计API调试 - 准备读取响应文本');
|
|
|
const responseText = await res.text();
|
|
|
- console.debug('用户消费统计API调试 - 原始响应文本(前200字符):', responseText.substring(0, 200));
|
|
|
- console.debug('用户消费统计API调试 - 响应长度:', responseText.length);
|
|
|
- console.debug('用户消费统计API调试 - 响应是否为HTML:', responseText.trim().startsWith('<!DOCTYPE') || responseText.trim().startsWith('<html'));
|
|
|
|
|
|
if (res.status !== 200) {
|
|
|
// 尝试解析错误响应为JSON
|
|
|
try {
|
|
|
const errorData = JSON.parse(responseText);
|
|
|
- console.error('用户消费统计API调试 - 错误响应数据:', errorData);
|
|
|
|
|
|
// 处理Zod验证错误
|
|
|
if (errorData.error?.name === 'ZodError') {
|
|
|
@@ -218,8 +208,6 @@ export const UserConsumptionTable: React.FC<UserConsumptionTableProps> = ({
|
|
|
|
|
|
throw new Error(errorData.message || errorData.error?.message || '获取用户消费统计失败');
|
|
|
} catch (jsonError) {
|
|
|
- console.error('用户消费统计API调试 - 无法解析错误响应为JSON:', jsonError);
|
|
|
- console.error('用户消费统计API调试 - 原始错误响应文本:', responseText.substring(0, 500));
|
|
|
throw new Error(`获取用户消费统计失败: ${res.status} ${responseText.substring(0, 100)}`);
|
|
|
}
|
|
|
}
|
|
|
@@ -227,48 +215,12 @@ export const UserConsumptionTable: React.FC<UserConsumptionTableProps> = ({
|
|
|
// 解析成功响应为JSON
|
|
|
try {
|
|
|
const responseData = JSON.parse(responseText);
|
|
|
- console.debug('用户消费统计API调试 - 解析后的数据:', responseData);
|
|
|
return responseData;
|
|
|
} catch (jsonError) {
|
|
|
- console.error('用户消费统计API调试 - JSON解析错误:', jsonError);
|
|
|
- console.error('用户消费统计API调试 - 无法解析的响应文本:', responseText);
|
|
|
throw new Error('API返回了无效的JSON响应');
|
|
|
}
|
|
|
} catch (error) {
|
|
|
console.error('获取用户消费统计失败:', error);
|
|
|
-
|
|
|
- // 记录响应对象状态(注意:响应体可能已被读取)
|
|
|
- console.error('用户消费统计API调试 - 响应对象状态:', {
|
|
|
- resExists: !!res,
|
|
|
- resType: typeof res,
|
|
|
- resStatus: res?.status,
|
|
|
- resOk: res?.ok,
|
|
|
- resHeaders: res ? Object.fromEntries(res.headers?.entries() || []) : '无响应',
|
|
|
- bodyUsed: res?.bodyUsed // 检查响应体是否已被使用
|
|
|
- });
|
|
|
-
|
|
|
- if (error instanceof Error) {
|
|
|
- console.error('用户消费统计API调试 - 错误详情:', {
|
|
|
- name: error.name,
|
|
|
- message: error.message,
|
|
|
- stack: error.stack
|
|
|
- });
|
|
|
-
|
|
|
- // 检查是否是JSON解析错误
|
|
|
- if (error.name === 'SyntaxError' && error.message.includes('JSON')) {
|
|
|
- console.error('用户消费统计API调试 - 检测到JSON解析错误,响应可能不是有效的JSON');
|
|
|
- }
|
|
|
- } else {
|
|
|
- console.error('用户消费统计API调试 - 未知错误类型:', error);
|
|
|
- }
|
|
|
-
|
|
|
- // 不再尝试读取响应文本,因为可能已经读取过了
|
|
|
- if (!res) {
|
|
|
- console.error('用户消费统计API调试 - 响应对象不存在,可能是网络错误或API调用失败');
|
|
|
- } else if (res.bodyUsed) {
|
|
|
- console.error('用户消费统计API调试 - 响应体已被读取,无法再次读取');
|
|
|
- }
|
|
|
-
|
|
|
throw error;
|
|
|
}
|
|
|
},
|
|
|
@@ -315,9 +267,11 @@ export const UserConsumptionTable: React.FC<UserConsumptionTableProps> = ({
|
|
|
|
|
|
// 处理刷新数据
|
|
|
const handleRefresh = useCallback(() => {
|
|
|
- refetchConsumption();
|
|
|
+ setForceRefresh(true);
|
|
|
toast.success('用户消费数据已刷新');
|
|
|
- }, [refetchConsumption]);
|
|
|
+ // 重置 forceRefresh 状态
|
|
|
+ setTimeout(() => setForceRefresh(false), 100);
|
|
|
+ }, []);
|
|
|
|
|
|
// 错误处理
|
|
|
useEffect(() => {
|