deploy-ease-platform/frontend/src/utils/page.ts
2025-11-28 13:09:24 +08:00

29 lines
946 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import type {Page} from '@/types/base';
// 默认分页参数
export const DEFAULT_PAGE_SIZE = 10;
export const DEFAULT_PAGE_NUM = 0; // 页码从0开始
/**
* 转换前端分页参数为后端分页参数
*/
export const convertToPageParams = (params?: {
current?: number;
pageSize?: number;
sortField?: string;
sortOrder?: string;
}): { sortOrder: any; sortField: string | undefined; pageSize: number; pageNum: number } => ({
pageNum: Math.max(0, (params?.current ?? 1) - 1), // 前端current从1开始转换为从0开始的页码
pageSize: params?.pageSize || DEFAULT_PAGE_SIZE,
sortField: params?.sortField,
sortOrder: params?.sortOrder?.replace('end', '')
});
/**
* 转换后端分页数据为前端分页数据
*/
export const convertToPageInfo = (page?: Page<any>) => ({
current: (page?.number || 0) + 1,
pageSize: page?.size || DEFAULT_PAGE_SIZE,
total: page?.totalElements || 0
});