diff --git a/src/views/Community/components/DynamicNews/DynamicNewsCard.js b/src/views/Community/components/DynamicNews/DynamicNewsCard.js index ab9f9f9f..bdfb7edc 100644 --- a/src/views/Community/components/DynamicNews/DynamicNewsCard.js +++ b/src/views/Community/components/DynamicNews/DynamicNewsCard.js @@ -377,11 +377,14 @@ const [currentMode, setCurrentMode] = useState('vertical'); // 添加防抖:如果已经初始化,不再执行 if (hasInitialized.current) return; + // mainline 模式使用 four-row 的 API 模式(共用数据) + const apiMode = mode === DISPLAY_MODES.MAINLINE ? DISPLAY_MODES.FOUR_ROW : mode; + // ⚡ 始终获取最新数据,确保用户每次进入页面看到最新事件 hasInitialized.current = true; - console.log('%c🚀 [初始加载] 获取最新事件数据', 'color: #10B981; font-weight: bold;', { mode, pageSize }); + console.log('%c🚀 [初始加载] 获取最新事件数据', 'color: #10B981; font-weight: bold;', { mode, apiMode, pageSize }); dispatch(fetchDynamicNews({ - mode: mode, // 传递当前模式 + mode: apiMode, // 传递 API 模式(mainline 映射为 four-row) per_page: pageSize, pageSize: pageSize, // 传递 pageSize 确保索引计算一致 clearCache: true, @@ -409,11 +412,14 @@ const [currentMode, setCurrentMode] = useState('vertical'); return; } - console.log('%c🔍 [筛选] 筛选条件改变,重新请求数据', 'color: #8B5CF6; font-weight: bold;', filters); + // mainline 模式使用 four-row 的 API 模式(共用数据) + const apiMode = mode === DISPLAY_MODES.MAINLINE ? DISPLAY_MODES.FOUR_ROW : mode; + + console.log('%c🔍 [筛选] 筛选条件改变,重新请求数据', 'color: #8B5CF6; font-weight: bold;', { filters, mode, apiMode }); // 筛选条件改变时,清空对应模式的缓存并从第1页开始加载 dispatch(fetchDynamicNews({ - mode: mode, // 传递当前模式 + mode: apiMode, // 传递 API 模式(mainline 映射为 four-row) per_page: pageSize, pageSize: pageSize, clearCache: true, // 清空缓存 @@ -444,14 +450,18 @@ const [currentMode, setCurrentMode] = useState('vertical'); console.log(`%c🔄 [模式切换] ${mode} 模式数据为空,开始加载`, 'color: #8B5CF6; font-weight: bold;'); // 🔧 根据 mode 直接计算 per_page,避免使用可能过时的 pageSize prop - const modePageSize = mode === DISPLAY_MODES.FOUR_ROW + // mainline 模式复用 four-row 的分页大小 + const modePageSize = (mode === DISPLAY_MODES.FOUR_ROW || mode === DISPLAY_MODES.MAINLINE) ? PAGINATION_CONFIG.FOUR_ROW_PAGE_SIZE // 30 : PAGINATION_CONFIG.VERTICAL_PAGE_SIZE; // 10 - console.log(`%c 计算的 per_page: ${modePageSize} (mode: ${mode})`, 'color: #8B5CF6;'); + // mainline 模式使用 four-row 的 API 模式(共用数据) + const apiMode = mode === DISPLAY_MODES.MAINLINE ? DISPLAY_MODES.FOUR_ROW : mode; + + console.log(`%c 计算的 per_page: ${modePageSize}, apiMode: ${apiMode} (mode: ${mode})`, 'color: #8B5CF6;'); dispatch(fetchDynamicNews({ - mode: mode, + mode: apiMode, // 使用映射后的 API 模式 per_page: modePageSize, // 使用计算的值,不是 pageSize prop pageSize: modePageSize, clearCache: true, @@ -459,7 +469,7 @@ const [currentMode, setCurrentMode] = useState('vertical'); page: PAGINATION_CONFIG.INITIAL_PAGE, // 然后覆盖 page 参数 })); } - }, [mode, currentMode, allCachedEventsByPage, allCachedEvents, dispatch]); // 移除 filters 依赖,避免与筛选 useEffect 循环触发 // 添加所有依赖 + }, [mode, currentMode, allCachedEventsByPage, allCachedEvents, dispatch, filters]); // 添加 filters 依赖 // 自动选中逻辑 - 只在首次加载时自动选中第一个事件,翻页时不自动选中 useEffect(() => { diff --git a/src/views/Community/hooks/useEventFilters.js b/src/views/Community/hooks/useEventFilters.js index 51206708..9113d755 100644 --- a/src/views/Community/hooks/useEventFilters.js +++ b/src/views/Community/hooks/useEventFilters.js @@ -28,9 +28,10 @@ export const useEventFilters = ({ navigate, onEventClick, eventTimelineRef } = { q: searchParams.get('q') || '', industry_code: searchParams.get('industry_code') || '', // 时间筛选参数(从 TradingTimeFilter 传递) + // 默认显示近一周数据(recent_days=7) start_date: searchParams.get('start_date') || '', end_date: searchParams.get('end_date') || '', - recent_days: searchParams.get('recent_days') || '', + recent_days: searchParams.get('recent_days') || '7', // 默认近一周 page: parseInt(searchParams.get('page') || '1', 10) }; });