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> {
|
2023-11-24 17:10:28 +08:00
|
|
|
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);
|
|
|
|
}
|