feat: 翻页bugfix
This commit is contained in:
@@ -193,22 +193,7 @@ export const usePagination = ({ allCachedEvents, total, cachedCount, dispatch, t
|
||||
cachedCount
|
||||
});
|
||||
|
||||
// 特殊处理:返回第一页 - 清空缓存重新加载
|
||||
if (newPage === 1) {
|
||||
logger.debug('DynamicNewsCard', '返回第一页,清空缓存重新加载');
|
||||
setCurrentPage(1);
|
||||
dispatch(fetchDynamicNews({
|
||||
mode: mode, // 传递 mode 参数
|
||||
per_page: pageSize,
|
||||
pageSize: pageSize,
|
||||
clearCache: true, // 清空缓存
|
||||
...filters, // 先展开筛选条件
|
||||
page: 1, // 然后覆盖 page 参数
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查目标页缓存状态
|
||||
// 检查目标页缓存状态(统一处理,包括第一页)
|
||||
const { isTargetPageCached, targetPageInfo } = checkTargetPageCache(newPage);
|
||||
|
||||
console.log(`%c🟡 [缓存检查] 目标页${newPage}缓存状态`, 'color: #EAB308; font-weight: bold;');
|
||||
@@ -275,18 +260,23 @@ export const usePagination = ({ allCachedEvents, total, cachedCount, dispatch, t
|
||||
|
||||
// 加载下一页(用于无限滚动)
|
||||
const loadNextPage = useCallback(async () => {
|
||||
if (currentPage >= totalPages || loadingPage !== null) {
|
||||
// 修复:使用 hasMore 判断而不是 currentPage >= totalPages
|
||||
// 原因:去重后 cachedCount 可能小于 total,但 currentPage 已达到 totalPages
|
||||
if (!hasMore || loadingPage !== null) {
|
||||
logger.debug('DynamicNewsCard', '无法加载下一页', {
|
||||
currentPage,
|
||||
totalPages,
|
||||
hasMore,
|
||||
cachedCount,
|
||||
total,
|
||||
loadingPage,
|
||||
reason: currentPage >= totalPages ? '已是最后一页' : '正在加载中'
|
||||
reason: !hasMore ? '已加载全部数据 (cachedCount >= total)' : '正在加载中'
|
||||
});
|
||||
return Promise.resolve(false); // 没有更多数据或正在加载
|
||||
}
|
||||
|
||||
const nextPage = currentPage + 1;
|
||||
logger.debug('DynamicNewsCard', '懒加载:加载下一页', { currentPage, nextPage });
|
||||
logger.debug('DynamicNewsCard', '懒加载:加载下一页', { currentPage, nextPage, hasMore, cachedCount, total });
|
||||
|
||||
try {
|
||||
await handlePageChange(nextPage);
|
||||
@@ -295,7 +285,7 @@ export const usePagination = ({ allCachedEvents, total, cachedCount, dispatch, t
|
||||
logger.error('DynamicNewsCard', '懒加载失败', error, { nextPage });
|
||||
return false;
|
||||
}
|
||||
}, [currentPage, totalPages, loadingPage, handlePageChange]);
|
||||
}, [currentPage, totalPages, hasMore, cachedCount, total, loadingPage, handlePageChange]);
|
||||
|
||||
// 加载上一页(用于双向无限滚动)
|
||||
const loadPrevPage = useCallback(async () => {
|
||||
@@ -326,17 +316,7 @@ export const usePagination = ({ allCachedEvents, total, cachedCount, dispatch, t
|
||||
|
||||
setMode(newMode);
|
||||
setCurrentPage(PAGINATION_CONFIG.INITIAL_PAGE);
|
||||
|
||||
const newPageSize = (() => {
|
||||
switch (newMode) {
|
||||
case DISPLAY_MODES.FOUR_ROW:
|
||||
return PAGINATION_CONFIG.FOUR_ROW_PAGE_SIZE;
|
||||
case DISPLAY_MODES.VERTICAL:
|
||||
return PAGINATION_CONFIG.VERTICAL_PAGE_SIZE;
|
||||
default:
|
||||
return PAGINATION_CONFIG.VERTICAL_PAGE_SIZE;
|
||||
}
|
||||
})();
|
||||
// pageSize 会根据 mode 自动重新计算(第35-44行)
|
||||
}, [mode]);
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user