// 通用列表分页器:沿用项目向导 pp-pager / 消费页 bill-pager 的视觉(mono 总数 + 页码窗口 + 每页条数)。 // 纯前端切片分页:父组件持有 page state,自己 slice;本组件只画控件。 // total <= pageSize 时不渲染(单页无需分页器)。 // 页码窗口:超过 7 页折叠成 1 … cur-1 cur cur+1 … last export function pageWindow(current: number, total: number): Array { if (total <= 7) return Array.from({ length: total }, (_, i) => i + 1); const items: Array = [1]; const start = Math.max(2, current - 1); const end = Math.min(total - 1, current + 1); if (start > 2) items.push("ellipsis"); for (let p = start; p <= end; p++) items.push(p); if (end < total - 1) items.push("ellipsis"); items.push(total); return items; } export function Pager({ page, total, pageSize, onChange }: { page: number; total: number; pageSize: number; onChange: (page: number) => void; }) { const totalPages = Math.max(1, Math.ceil(total / pageSize)); const cur = Math.min(Math.max(1, page), totalPages); if (total <= pageSize) return null; return (
// 共 {total} 条 · 第 {cur} / {totalPages} 页
{pageWindow(cur, totalPages).map((p, i) => ( p === "ellipsis" ? … : ))}
每页 {pageSize} 条
); }