iter(g170): 分页器支持极简模式与单页隐藏

This commit is contained in:
HIsheR
2026-10-26 16:17:05 +08:00
parent 8c9541d209
commit a754bd6b25
7 changed files with 60 additions and 5 deletions
+9 -1
View File
@@ -16,7 +16,7 @@ function pageSequence(page: number, totalPages: number): (number | null)[] {
return seq;
}
/*** 独立分页器:受控组件,page 为双向绑定信号;页码过多折叠省略号,首末页禁用翻页,jumpable 可跳页,pageSizes 可切每页条数 ***/
/*** 独立分页器:受控组件,page 为双向绑定信号;页码过多折叠省略号,首末页禁用翻页,jumpable 可跳页,pageSizes 可切每页条数,simple 走极简、hideOnSinglePage 单页隐藏 ***/
export function pagination(props: PaginationProps): HTMLElement {
// —— 状态集中声明 ——
@@ -61,6 +61,14 @@ export function pagination(props: PaginationProps): HTMLElement {
renderList(pages, () => {
const totalNow = totalPages();
const page = Math.min(totalNow, Math.max(1, props.page()));
nav.hidden = Boolean(props.hideOnSinglePage) && totalNow <= 1; // 单页时整块隐藏,工具栏不必为它留位
if (props.simple) { // 极简态:页码不给点,只留前后翻页与进度文字
return [
h('button', { class: 'ua-page-btn', disabled: page <= 1, 'aria-label': '上一页', onClick: () => go(page - 1) }, '‹'),
h('span', { class: 'ua-page-simple', 'aria-live': 'polite' }, `${page} / ${totalNow}`),
h('button', { class: 'ua-page-btn', disabled: page >= totalNow, 'aria-label': '下一页', onClick: () => go(page + 1) }, '›'),
];
}
const items: HTMLElement[] = [h('button', { class: 'ua-page-btn', disabled: page <= 1, 'aria-label': '上一页', onClick: () => go(page - 1) }, '‹')];
for (const it of pageSequence(page, totalNow)) {
items.push(