From 6271736969e8eba3a41586aa4b7504b9729788b4 Mon Sep 17 00:00:00 2001 From: zdl <3489966805@qq.com> Date: Thu, 6 Nov 2025 18:00:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=87=8D=E7=BD=AE?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E4=B8=8D=E7=94=9F=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题描述: - 用户选择所有筛选条件后,点击"重置"按钮无反应 - 筛选条件未被清空,事件列表未重新加载 根本原因: - 当筛选条件从"有值"重置为"空值"或从"空值"重置为"空值"时 - 如果 filters 对象的字段值没有实质变化 - DynamicNewsCard 的 useEffect 依赖项检测不到变化,不会触发重新加载 解决方案: 1. UnifiedSearchBox.handleReset() 添加 _forceRefresh 时间戳标志 - 每次重置都生成唯一的 Date.now() 时间戳 - 确保 filters 对象每次重置都不同 2. DynamicNewsCard 筛选 useEffect 依赖数组添加 filters._forceRefresh - 监听强制刷新标志的变化 - 即使其他筛选条件未变,也能触发重新加载 3. 增强调试日志 - 添加完整的重置流程日志输出 - 便于排查后续问题 修改文件: - src/views/Community/components/UnifiedSearchBox.js (Line 505-536) - src/views/Community/components/DynamicNewsCard.js (Line 264) 测试场景: ✅ 选择所有筛选条件后点击重置 - 清空并重新加载 ✅ 未选择筛选条件时点击重置 - 强制刷新第1页 ✅ 重置后 Redux 缓存被清空 (clearCache: true) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/views/Community/components/DynamicNewsCard.js | 1 + src/views/Community/components/UnifiedSearchBox.js | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/views/Community/components/DynamicNewsCard.js b/src/views/Community/components/DynamicNewsCard.js index 085ed926..e6149235 100644 --- a/src/views/Community/components/DynamicNewsCard.js +++ b/src/views/Community/components/DynamicNewsCard.js @@ -261,6 +261,7 @@ const [currentMode, setCurrentMode] = useState('vertical'); filters.end_date, // 时间筛选参数:结束时间 filters.recent_days, // 时间筛选参数:近N天 filters.industry_code, + filters._forceRefresh, // 强制刷新标志(用于重置按钮) mode, // 添加 mode 到依赖 pageSize, // 添加 pageSize 到依赖 dispatch diff --git a/src/views/Community/components/UnifiedSearchBox.js b/src/views/Community/components/UnifiedSearchBox.js index a8a57221..a611e08f 100644 --- a/src/views/Community/components/UnifiedSearchBox.js +++ b/src/views/Community/components/UnifiedSearchBox.js @@ -503,6 +503,8 @@ const UnifiedSearchBox = ({ // ✅ 重置筛选 - 清空所有筛选器并触发搜索 const handleReset = () => { + console.log('%c🔄 [重置] 开始重置筛选条件', 'color: #FF4D4F; font-weight: bold;'); + // 重置所有筛选器状态 setInputValue(''); // 清空输入框 setStockOptions([]); @@ -520,11 +522,17 @@ const UnifiedSearchBox = ({ start_date: '', end_date: '', recent_days: '', - page: 1 + page: 1, + _forceRefresh: Date.now() // 添加强制刷新标志,确保每次重置都触发更新 }; + console.log('%c🔄 [重置] 重置参数', 'color: #FF4D4F;', resetParams); logger.debug('UnifiedSearchBox', '重置筛选', resetParams); + + console.log('%c🔄 [重置] 调用 onSearch', 'color: #FF4D4F;', typeof onSearch); onSearch(resetParams); + + console.log('%c✅ [重置] 重置完成', 'color: #52C41A; font-weight: bold;'); }; // 生成已选条件标签(包含所有筛选条件) - 从 filters 和本地状态读取