更新筛选状态不及时问题

This commit is contained in:
张成
2025-11-23 00:36:19 +08:00
parent 8b3f6c5a3a
commit b258ba58fe
2 changed files with 420 additions and 4 deletions

View File

@@ -498,13 +498,18 @@ export const useListStore = create<TennisStore>()((set, get) => ({
const filterOptions = { ...currentPageState?.filterOptions, ...payload };
const filterCount = Object.values(filterOptions).filter(Boolean).length;
// 先更新状态
state.updateCurrentPageState({
filterOptions,
filterCount,
pageOption: defaultPageOption,
});
// 获取球局数量
state.fetchGetGamesCount();
// 使用 Promise.resolve 确保状态更新后再调用接口
Promise.resolve().then(() => {
const freshState = get(); // 重新获取最新状态
freshState.fetchGetGamesCount();
});
},
// 更新距离和快捷筛选
@@ -513,13 +518,19 @@ export const useListStore = create<TennisStore>()((set, get) => ({
const { currentPageState } = state.getCurrentPageState();
const { distanceQuickFilter } = currentPageState || {};
const newDistanceQuickFilter = { ...distanceQuickFilter, ...payload };
// 先更新状态
state.updateCurrentPageState({
distanceQuickFilter: newDistanceQuickFilter,
pageOption: defaultPageOption,
});
state.getMatchesData();
state.fetchGetGamesCount();
// 使用 Promise.resolve 确保状态更新后再调用接口
Promise.resolve().then(() => {
const freshState = get(); // 重新获取最新状态
freshState.getMatchesData();
freshState.fetchGetGamesCount();
});
},
// 清空综合筛选选项