Skip to content

Commit 570c72d

Browse files
committed
feat: 调整图像分页功能,优化样式和交互体验;更新隐藏状态处理
1 parent 92e0cfb commit 570c72d

2 files changed

Lines changed: 68 additions & 32 deletions

File tree

public/assets/admin/filters.js

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { $, $$, adminHref } from './utils.js';
22

3-
const imagePageSize = 24;
3+
const imagePageSize = 15;
44
const imageSearchKey = 'nyaovo:imageSearch';
55
const 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

public/assets/style.css

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,10 @@ input[type="file"] {
12201220
transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
12211221
}
12221222

1223+
.image-card[hidden] {
1224+
display: none;
1225+
}
1226+
12231227
.image-card:hover {
12241228
border-color: var(--line-strong);
12251229
box-shadow: 0 14px 30px rgba(23, 32, 51, 0.08);
@@ -2584,23 +2588,38 @@ input[type="file"] {
25842588
}
25852589
}
25862590

2587-
/* Pagination numbers */
25882591
.pagination-row {
25892592
display: flex;
25902593
align-items: center;
25912594
justify-content: center;
2592-
gap: 6px;
2595+
gap: 8px;
25932596
flex-wrap: wrap;
2594-
margin-top: 12px;
2597+
width: fit-content;
2598+
max-width: 100%;
2599+
margin: 16px auto 0;
2600+
padding: 8px;
2601+
border: 1px solid var(--line);
2602+
border-radius: 999px;
2603+
background: var(--surface-soft);
25952604
}
25962605

25972606
.pagination-row button {
2598-
min-width: 36px;
2599-
min-height: 36px;
2600-
padding: 0 8px;
2601-
border-radius: 6px;
2602-
font-size: 0.85rem;
2603-
font-weight: 700;
2607+
min-width: 34px;
2608+
min-height: 34px;
2609+
padding: 0 11px;
2610+
color: var(--text);
2611+
background: var(--surface);
2612+
border-color: var(--line);
2613+
border-radius: 999px;
2614+
box-shadow: none;
2615+
font-size: 0.84rem;
2616+
font-weight: 800;
2617+
}
2618+
2619+
.pagination-row button:hover:not(:disabled) {
2620+
color: var(--primary-dark);
2621+
background: var(--primary-soft);
2622+
border-color: #b8c9f7;
26042623
}
26052624

26062625
.pagination-row button.active {
@@ -2610,10 +2629,18 @@ input[type="file"] {
26102629
}
26112630

26122631
.pagination-row button:disabled {
2613-
opacity: 0.4;
2632+
color: var(--muted);
2633+
background: transparent;
2634+
border-color: transparent;
2635+
opacity: 0.55;
26142636
cursor: not-allowed;
26152637
}
26162638

2639+
.pagination-ellipsis {
2640+
color: var(--muted);
2641+
font-weight: 800;
2642+
}
2643+
26172644
/* Collapsible sections */
26182645
.collapsed {
26192646
display: none;
@@ -2635,8 +2662,9 @@ input[type="file"] {
26352662
}
26362663

26372664
.pagination-row button {
2638-
min-width: 40px;
2639-
min-height: 40px;
2640-
font-size: 0.9rem;
2665+
min-width: 38px;
2666+
min-height: 38px;
2667+
padding: 0 10px;
2668+
font-size: 0.88rem;
26412669
}
26422670
}

0 commit comments

Comments
 (0)