fix: 修复模式切换时丢失筛选条件的问题

问题描述:
- 用户在单排/双排/纵向模式下应用筛选条件后,切换到平铺模式时筛选条件丢失
- usePagination hook 在模式切换时重新请求数据,但未传递筛选参数

修复内容:
1. usePagination.js
   - 新增 filters 参数接收筛选条件
   - handleModeToggle 函数在发起请求时应用 ...filters
   - 将 filters 添加到依赖数组,确保筛选条件变化时重新执行

2. DynamicNewsCard.js
   - 将 filters 传递给 usePagination hook
   - 确保筛选条件在模式切换时保持一致

影响范围:
- 所有展示模式切换(单排、双排、纵向、平铺)

测试建议:
1. 应用任意筛选条件(如排序、重要性、关键词)
2. 切换到平铺模式
3. 验证筛选条件是否保持生效

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
zdl
2025-11-05 09:35:35 +08:00
parent b223be2f01
commit 64de7d055b
2 changed files with 7 additions and 4 deletions

View File

@@ -113,7 +113,8 @@ const DynamicNewsCard = forwardRef(({
total, total,
cachedCount, cachedCount,
dispatch, dispatch,
toast toast,
filters // 传递筛选条件
}); });
// 四排模式的事件点击处理(打开弹窗) // 四排模式的事件点击处理(打开弹窗)

View File

@@ -19,9 +19,10 @@ import {
* @param {number} options.cachedCount - 已缓存数量 * @param {number} options.cachedCount - 已缓存数量
* @param {Function} options.dispatch - Redux dispatch 函数 * @param {Function} options.dispatch - Redux dispatch 函数
* @param {Function} options.toast - Toast 通知函数 * @param {Function} options.toast - Toast 通知函数
* @param {Object} options.filters - 筛选条件
* @returns {Object} 分页状态和方法 * @returns {Object} 分页状态和方法
*/ */
export const usePagination = ({ allCachedEvents, total, cachedCount, dispatch, toast }) => { export const usePagination = ({ allCachedEvents, total, cachedCount, dispatch, toast, filters = {} }) => {
// 本地状态 // 本地状态
const [currentPage, setCurrentPage] = useState(PAGINATION_CONFIG.INITIAL_PAGE); const [currentPage, setCurrentPage] = useState(PAGINATION_CONFIG.INITIAL_PAGE);
const [loadingPage, setLoadingPage] = useState(null); const [loadingPage, setLoadingPage] = useState(null);
@@ -314,11 +315,12 @@ export const usePagination = ({ allCachedEvents, total, cachedCount, dispatch, t
page: 1, page: 1,
per_page: newPageSize, per_page: newPageSize,
pageSize: newPageSize, // 传递 pageSize 确保索引计算一致 pageSize: newPageSize, // 传递 pageSize 确保索引计算一致
clearCache: true clearCache: true,
...filters // 应用筛选条件
})); }));
} }
// 如果第1页数据完整不发起请求直接切换 // 如果第1页数据完整不发起请求直接切换
}, [mode, allCachedEvents, total, dispatch]); }, [mode, allCachedEvents, total, dispatch, filters]);
return { return {
// 状态 // 状态