2024-07-15 00:30:33 +08:00
|
|
|
import { IContext } from "../core/index.js";
|
2022-12-27 12:32:09 +08:00
|
|
|
|
|
|
|
|
export type UserContext = IContext;
|
|
|
|
|
export type PipelineContext = IContext;
|
2025-05-28 00:57:52 +08:00
|
|
|
|
2025-06-29 19:36:46 +08:00
|
|
|
export type PageSearch = {
|
2025-05-28 00:57:52 +08:00
|
|
|
offset?: number;
|
|
|
|
|
limit?: number;
|
2025-05-28 11:22:39 +08:00
|
|
|
searchKey?: string;
|
|
|
|
|
// sortBy?: string;
|
|
|
|
|
// sortOrder?: "asc" | "desc";
|
2025-05-28 00:57:52 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export type PageRes = {
|
|
|
|
|
offset?: number;
|
|
|
|
|
limit?: number;
|
|
|
|
|
total?: string;
|
|
|
|
|
list: any[];
|
|
|
|
|
};
|
2025-06-29 19:36:46 +08:00
|
|
|
|
|
|
|
|
export class Pager {
|
|
|
|
|
offset: number;
|
|
|
|
|
limit: number;
|
|
|
|
|
constructor(req: PageSearch) {
|
|
|
|
|
this.offset = req.offset ?? 0;
|
|
|
|
|
this.limit = req.limit || 50;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getPageNo() {
|
|
|
|
|
const size = this.limit;
|
|
|
|
|
const offset = this.offset;
|
|
|
|
|
let page = Math.floor(offset / size);
|
|
|
|
|
if (offset % size === 0) {
|
|
|
|
|
page++;
|
|
|
|
|
}
|
|
|
|
|
return page;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setPageNo(pageNo: number) {
|
|
|
|
|
this.offset = (pageNo - 1) * (this.limit ?? 50);
|
|
|
|
|
}
|
|
|
|
|
}
|