forked from izu/student-web-if-development-kit
refactor(tapops): modularize page code
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user