11import { $ , $$ , adminHref } from './utils.js' ;
22
3- const imagePageSize = 24 ;
3+ const imagePageSize = 15 ;
44const imageSearchKey = 'nyaovo:imageSearch' ;
55const imageSortKey = 'nyaovo:imageSort' ;
66
@@ -12,7 +12,7 @@ export function initFilters({ updateBatchState }) {
1212 const resetImageFilters = $ ( '#resetImageFilters' ) ;
1313 const loadMoreImages = $ ( '#loadMoreImages' ) ;
1414 const loadMoreStatus = $ ( '#loadMoreStatus' ) ;
15- let visibleImageLimit = imagePageSize ;
15+ const loadMoreRow = $ ( '.load-more-row' ) ;
1616 let filterLoading = false ;
1717 let currentPathSearch = `${ window . location . pathname } ${ window . location . search } ` ;
1818 let currentPage = 1 ;
@@ -70,11 +70,14 @@ export function initFilters({ updateBatchState }) {
7070
7171 if ( totalPages <= 1 ) {
7272 paginationRow . innerHTML = '' ;
73+ paginationRow . hidden = true ;
7374 return ;
7475 }
7576
77+ paginationRow . hidden = false ;
78+
7679 let html = '' ;
77- html += `<button data-page="${ currentPage - 1 } " ${ currentPage === 1 ? 'disabled' : '' } >\u25C0 </button>` ;
80+ html += `<button class="page-nav" data-page="${ currentPage - 1 } " ${ currentPage === 1 ? 'disabled' : '' } aria-label="上一页">上一页 </button>` ;
7881
7982 const maxVisible = 5 ;
8083 let start = Math . max ( 1 , currentPage - Math . floor ( maxVisible / 2 ) ) ;
@@ -84,20 +87,20 @@ export function initFilters({ updateBatchState }) {
8487 }
8588
8689 if ( start > 1 ) {
87- html += ` <button data-page="1">1</button>` ;
88- if ( start > 2 ) html += ` <span style="color:var(--muted) ">...</span>` ;
90+ html += ' <button class="page-number" data-page="1">1</button>' ;
91+ if ( start > 2 ) html += ' <span class="pagination-ellipsis ">...</span>' ;
8992 }
9093
9194 for ( let i = start ; i <= end ; i ++ ) {
92- html += `<button data-page="${ i } " class=" ${ i === currentPage ? 'active ' : '' } " >${ i } </button>` ;
95+ html += `<button class="page-number ${ i === currentPage ? 'active' : '' } " data-page="${ i } " ${ i === currentPage ? 'aria-current="page" ' : '' } >${ i } </button>` ;
9396 }
9497
9598 if ( end < totalPages ) {
96- if ( end < totalPages - 1 ) html += ` <span style="color:var(--muted) ">...</span>` ;
97- html += `<button data-page="${ totalPages } ">${ totalPages } </button>` ;
99+ if ( end < totalPages - 1 ) html += ' <span class="pagination-ellipsis ">...</span>' ;
100+ html += `<button class="page-number" data-page="${ totalPages } ">${ totalPages } </button>` ;
98101 }
99102
100- html += `<button data-page="${ currentPage + 1 } " ${ currentPage === totalPages ? 'disabled' : '' } >\u25B6 </button>` ;
103+ html += `<button class="page-nav" data-page="${ currentPage + 1 } " ${ currentPage === totalPages ? 'disabled' : '' } aria-label="下一页">下一页 </button>` ;
101104
102105 paginationRow . innerHTML = html ;
103106
@@ -106,7 +109,6 @@ export function initFilters({ updateBatchState }) {
106109 const page = parseInt ( btn . dataset . page , 10 ) ;
107110 if ( page >= 1 && page <= totalPages ) {
108111 currentPage = page ;
109- visibleImageLimit = page * imagePageSize ;
110112 applyImageFilters ( { resetPage : false } ) ;
111113 const section = document . getElementById ( 'images' ) ;
112114 if ( section ) section . scrollIntoView ( { behavior : 'smooth' , block : 'start' } ) ;
@@ -118,7 +120,6 @@ export function initFilters({ updateBatchState }) {
118120 function applyImageFilters ( { resetPage = true } = { } ) {
119121 if ( ! imageGrid ) return ;
120122 if ( resetPage ) {
121- visibleImageLimit = imagePageSize ;
122123 currentPage = 1 ;
123124 }
124125
@@ -133,19 +134,28 @@ export function initFilters({ updateBatchState }) {
133134 card . dataset . filteredVisible = 'false' ;
134135 } ) ;
135136
136- matched . slice ( 0 , visibleImageLimit ) . forEach ( ( card ) => {
137+ const totalPages = Math . max ( 1 , Math . ceil ( matched . length / imagePageSize ) ) ;
138+ currentPage = Math . min ( currentPage , totalPages ) ;
139+ const startIndex = ( currentPage - 1 ) * imagePageSize ;
140+ const visibleCards = matched . slice ( startIndex , startIndex + imagePageSize ) ;
141+
142+ visibleCards . forEach ( ( card ) => {
137143 card . hidden = false ;
138144 card . dataset . filteredVisible = 'true' ;
139145 } ) ;
140146
141147 if ( imageResultCount ) {
142- imageResultCount . textContent = `当前 ${ matched . length } 张,已显示 ${ Math . min ( matched . length , visibleImageLimit ) } 张` ;
148+ if ( matched . length ) {
149+ imageResultCount . textContent = `当前 ${ matched . length } 张,第 ${ currentPage } / ${ totalPages } 页,每页最多 ${ imagePageSize } 张` ;
150+ } else {
151+ imageResultCount . textContent = '当前 0 张' ;
152+ }
143153 }
144154
145- const hasMore = matched . length > visibleImageLimit ;
146- if ( loadMoreImages ) loadMoreImages . hidden = ! hasMore ;
155+ if ( loadMoreImages ) loadMoreImages . hidden = true ;
156+ if ( loadMoreRow ) loadMoreRow . hidden = true ;
147157 if ( loadMoreStatus ) {
148- loadMoreStatus . textContent = hasMore ? `还有 ${ matched . length - visibleImageLimit } 张` : matched . length ? '已全部显示' : '无匹配图片' ;
158+ loadMoreStatus . textContent = matched . length ? `本页显示 ${ visibleCards . length } 张` : '无匹配图片' ;
149159 }
150160
151161 renderPagination ( matched . length ) ;
@@ -174,7 +184,6 @@ export function initFilters({ updateBatchState }) {
174184
175185 filters . innerHTML = nextFilters . innerHTML ;
176186 imageGrid . innerHTML = nextGrid . innerHTML ;
177- visibleImageLimit = imagePageSize ;
178187 currentPage = 1 ;
179188 applyImageFilters ( ) ;
180189
@@ -221,8 +230,7 @@ export function initFilters({ updateBatchState }) {
221230 } ) ;
222231
223232 loadMoreImages ?. addEventListener ( 'click' , ( ) => {
224- visibleImageLimit += imagePageSize ;
225- currentPage = Math . ceil ( visibleImageLimit / imagePageSize ) ;
233+ currentPage += 1 ;
226234 applyImageFilters ( { resetPage : false } ) ;
227235 } ) ;
228236
0 commit comments