diff --git a/src/views/Community/components/DynamicNewsCard.js b/src/views/Community/components/DynamicNewsCard.js index aefd5f32..524b3575 100644 --- a/src/views/Community/components/DynamicNewsCard.js +++ b/src/views/Community/components/DynamicNewsCard.js @@ -227,8 +227,8 @@ const [currentMode, setCurrentMode] = useState('vertical'); // ========== 纵向模式 ========== // 只在第1页时刷新,避免打断用户浏览其他页 if (state.currentPage === 1) { - console.log('[DynamicNewsCard] 纵向模式 + 第1页 → 刷新列表'); - handlePageChange(1); // 清空缓存并刷新第1页 + console.log('[DynamicNewsCard] 纵向模式 + 第1页 → 强制刷新列表'); + handlePageChange(1, true); // ⚡ 传递 force = true,强制刷新第1页 toast({ title: '检测到新事件', status: 'info', diff --git a/src/views/Community/components/DynamicNewsCard/hooks/usePagination.js b/src/views/Community/components/DynamicNewsCard/hooks/usePagination.js index b9f1ad1c..72e3790b 100644 --- a/src/views/Community/components/DynamicNewsCard/hooks/usePagination.js +++ b/src/views/Community/components/DynamicNewsCard/hooks/usePagination.js @@ -158,7 +158,11 @@ export const usePagination = ({ }, [dispatch, pageSize, toast, mode]); // 移除 filters 依赖,使用 filtersRef 读取最新值 // 翻页处理(第1页强制刷新 + 其他页缓存) - const handlePageChange = useCallback(async (newPage) => { + const handlePageChange = useCallback(async (newPage, force = false) => { + // force 参数:是否强制刷新(绕过"重复点击"检查) + // - true: 强制刷新(Socket 新事件触发) + // - false: 正常翻页(用户点击分页按钮) + // 边界检查 1: 检查页码范围 if (newPage < 1 || newPage > totalPages) { console.log(`%c⚠️ [翻页] 页码超出范围: ${newPage}`, 'color: #DC2626; font-weight: bold;'); @@ -166,13 +170,19 @@ export const usePagination = ({ return; } - // 边界检查 2: 检查是否重复点击 - if (newPage === currentPage) { + // 边界检查 2: 检查是否重复点击(强制刷新时绕过此检查) + if (!force && newPage === currentPage) { console.log(`%c⚠️ [翻页] 重复点击当前页: ${newPage}`, 'color: #EAB308; font-weight: bold;'); logger.debug('usePagination', '页码未改变', { newPage }); return; } + // ⚡ 如果是强制刷新(force = true),即使页码相同也继续执行 + if (force && newPage === currentPage) { + console.log(`%c🔄 [翻页] 强制刷新当前页: ${newPage}`, 'color: #10B981; font-weight: bold;'); + logger.info('usePagination', '强制刷新当前页', { newPage }); + } + // 边界检查 3: 防止竞态条件 - 只拦截相同页面的重复请求 if (loadingPage === newPage) { console.log(`%c⚠️ [翻页] 第${newPage}页正在加载中,忽略重复请求`, 'color: #EAB308; font-weight: bold;');