更新筛选状态不及时问题
This commit is contained in:
@@ -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();
|
||||
});
|
||||
},
|
||||
|
||||
// 清空综合筛选选项
|
||||
|
||||
Reference in New Issue
Block a user