fix: 修复重置按钮不生效问题

问题描述:
- 用户选择所有筛选条件后,点击"重置"按钮无反应
- 筛选条件未被清空,事件列表未重新加载

根本原因:
- 当筛选条件从"有值"重置为"空值"或从"空值"重置为"空值"时
- 如果 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 <noreply@anthropic.com>
This commit is contained in:
zdl
2025-11-06 18:00:53 +08:00
parent 319a78d34c
commit 6271736969
2 changed files with 10 additions and 1 deletions

View File

@@ -261,6 +261,7 @@ const [currentMode, setCurrentMode] = useState('vertical');
filters.end_date, // 时间筛选参数:结束时间 filters.end_date, // 时间筛选参数:结束时间
filters.recent_days, // 时间筛选参数近N天 filters.recent_days, // 时间筛选参数近N天
filters.industry_code, filters.industry_code,
filters._forceRefresh, // 强制刷新标志(用于重置按钮)
mode, // 添加 mode 到依赖 mode, // 添加 mode 到依赖
pageSize, // 添加 pageSize 到依赖 pageSize, // 添加 pageSize 到依赖
dispatch dispatch

View File

@@ -503,6 +503,8 @@ const UnifiedSearchBox = ({
// ✅ 重置筛选 - 清空所有筛选器并触发搜索 // ✅ 重置筛选 - 清空所有筛选器并触发搜索
const handleReset = () => { const handleReset = () => {
console.log('%c🔄 [重置] 开始重置筛选条件', 'color: #FF4D4F; font-weight: bold;');
// 重置所有筛选器状态 // 重置所有筛选器状态
setInputValue(''); // 清空输入框 setInputValue(''); // 清空输入框
setStockOptions([]); setStockOptions([]);
@@ -520,11 +522,17 @@ const UnifiedSearchBox = ({
start_date: '', start_date: '',
end_date: '', end_date: '',
recent_days: '', recent_days: '',
page: 1 page: 1,
_forceRefresh: Date.now() // 添加强制刷新标志,确保每次重置都触发更新
}; };
console.log('%c🔄 [重置] 重置参数', 'color: #FF4D4F;', resetParams);
logger.debug('UnifiedSearchBox', '重置筛选', resetParams); logger.debug('UnifiedSearchBox', '重置筛选', resetParams);
console.log('%c🔄 [重置] 调用 onSearch', 'color: #FF4D4F;', typeof onSearch);
onSearch(resetParams); onSearch(resetParams);
console.log('%c✅ [重置] 重置完成', 'color: #52C41A; font-weight: bold;');
}; };
// 生成已选条件标签(包含所有筛选条件) - 从 filters 和本地状态读取 // 生成已选条件标签(包含所有筛选条件) - 从 filters 和本地状态读取