17 lines
502 B
JavaScript
17 lines
502 B
JavaScript
export class PaginationModel {
|
|
static range(current, total) {
|
|
if (total <= 7) return Array.from({ length: total }, (_, index) => index + 1);
|
|
|
|
const pages = [1];
|
|
const low = Math.max(2, current - 1);
|
|
const high = Math.min(total - 1, current + 1);
|
|
|
|
if (low > 2) pages.push('...');
|
|
for (let page = low; page <= high; page += 1) pages.push(page);
|
|
if (high < total - 1) pages.push('...');
|
|
pages.push(total);
|
|
|
|
return pages;
|
|
}
|
|
}
|