Commit 97d953a022e08f6baa639ee65bd404e3da77c1d3

Authored by boyang
1 parent 55b538f1

fix: 修改客户列表

src/pages/Client/Client/index.tsx
... ... @@ -409,55 +409,28 @@ export default () => {
409 409 // 获取分页参数
410 410 const { current, pageSize, ...restParams } = params;
411 411  
412   - try {
413   - const res = await postAdminClientQueryClientPage({
414   - data: {
415   - ...restParams,
416   - groupFilter: groupFilter,
417   - // 明确传递分页参数
418   - current: current,
419   - pageSize: pageSize,
420   - },
421   - });
  412 + const res = await postAdminClientQueryClientPage({
  413 + data: {
  414 + ...restParams,
  415 + groupFilter: groupFilter,
  416 + // 明确传递分页参数
  417 + current: current,
  418 + pageSize: pageSize,
  419 + },
  420 + });
422 421  
423   - console.log('API Response:', res); // 添加日志来查看API返回的数据结构
424   - console.log('API Response data:', res.data); // 查看data部分的结构
  422 + // 处理后端返回的实际数据格式
  423 + // 根据提供的JSON,格式已经是 {records, total, current, pages, size, count}
  424 + const result = {
  425 + data: res.data?.records || [], // 数据源是 records 数组
  426 + success: true,
  427 + total: res.data?.total || 0, // 总记录数
  428 + // 返回服务器端的分页信息,让ProTable使用
  429 + current: res.data?.current || 1,
  430 + pageSize: res.data?.size || 10,
  431 + };
425 432  
426   - // 检查返回数据结构
427   - if (!res.data) {
428   - console.error('API response data is undefined');
429   - return { data: [], success: false, total: 0 };
430   - }
431   -
432   - // 根据API返回的数据结构调整处理方式
433   - let records = [];
434   - let total = 0;
435   -
436   - // 处理两种可能的数据结构
437   - if (res.data.records) {
438   - // 标准分页结构 {records, total, current, pages, size}
439   - records = res.data.records;
440   - total = res.data.total || 0;
441   - } else if (Array.isArray(res.data)) {
442   - // 直接返回数组的情况
443   - records = res.data;
444   - total = res.data.length;
445   - }
446   -
447   - const result = {
448   - data: records,
449   - success: true,
450   - total: total,
451   - current: res.data.current || current || 1,
452   - pageSize: res.data.size || pageSize || 10,
453   - };
454   -
455   - console.log('Processed result for ProTable:', result);
456   - return result;
457   - } catch (error) {
458   - console.error('Error fetching client data:', error);
459   - return { data: [], success: false, total: 0 };
460   - }
  433 + return result;
461 434 }}
462 435 search={{
463 436 labelWidth: 'auto',
... ...