bill-fontend/src/api/list.ts

44 lines
787 B
TypeScript
Raw Normal View History

2023-11-16 17:11:49 +08:00
import axios from 'axios';
import qs from 'query-string';
export interface Pageable {
pageNumber: number;
pageSize: number;
sort: {
sorted: boolean;
unsorted: boolean;
empty: boolean;
};
offset: number;
paged: boolean;
}
export interface ListParams<Record> {
page: number;
size: number;
2023-11-16 17:11:49 +08:00
}
export interface ListRes<Record> {
content: Record[];
totalPages: number;
totalElements: number;
size: number;
number: number;
pageable: Pageable;
}
export function queryList<Record>(
url: string,
params: ListParams<Record> | undefined
) {
if (params) {
return axios.get<ListRes<Record>>(url, {
params,
paramsSerializer: (obj) => {
return qs.stringify(obj);
},
});
};
return axios.get<ListRes<Record>>(url);
}