diff --git a/js/feed.js b/js/feed.js
index a1ec8e2..e1e711d 100644
--- a/js/feed.js
+++ b/js/feed.js
@@ -3,27 +3,26 @@
// ============================================================
let currentSort = 'latest';
-
let totalPages = 1;
const PAGE_SIZE = 20;
function renderFeed() {
const container = document.getElementById('postList');
container.innerHTML = '
加载中...
';
- API.getPosts(currentSort, currentPage, PAGE_SIZE).then(result => {
+ API.getPosts(currentSort, currentPageNum, PAGE_SIZE).then(result => {
const posts = result.data || [];
const pagination = result.pagination || { total: 0, totalPages: 1, page: 1 };
totalPages = pagination.totalPages || 1;
- currentPage = pagination.page || 1;
+ currentPageNum = pagination.page || 1;
- if (posts.length === 0 && currentPage === 1) {
+ if (posts.length === 0 && currentPageNum === 1) {
container.innerHTML =
'✨ 还没有帖子,快来发布第一条吧!
';
return;
}
- if (posts.length === 0 && currentPage > 1) {
- currentPage = 1;
+ if (posts.length === 0 && currentPageNum > 1) {
+ currentPageNum = 1;
renderFeed();
return;
}
@@ -73,32 +72,26 @@ function renderFeed() {
});
container.innerHTML = html;
- // ============================================================
- // 完整分页控件
- // ============================================================
+ // 分页控件
if (totalPages > 1) {
let paginationHtml = `
-
`;
- // 显示页码按钮
- let startPage = Math.max(1, currentPage - 4);
- let endPage = Math.min(totalPages, currentPage + 4);
+ let startPage = Math.max(1, currentPageNum - 4);
+ let endPage = Math.min(totalPages, currentPageNum + 4);
- // 如果当前页靠近开头,显示更多后面的页
- if (currentPage <= 4) {
+ if (currentPageNum <= 4) {
endPage = Math.min(totalPages, 9);
}
- // 如果当前页靠近结尾,显示更多前面的页
- if (currentPage > totalPages - 4) {
+ if (currentPageNum > totalPages - 4) {
startPage = Math.max(1, totalPages - 8);
}
- // 第一页
if (startPage > 1) {
paginationHtml += ``;
if (startPage > 2) {
@@ -107,7 +100,7 @@ function renderFeed() {
}
for (let i = startPage; i <= endPage; i++) {
- const isActive = i === currentPage;
+ const isActive = i === currentPageNum;
paginationHtml += `