diff --git a/src/pages/list/index.tsx b/src/pages/list/index.tsx index 0138f87..502a3ce 100644 --- a/src/pages/list/index.tsx +++ b/src/pages/list/index.tsx @@ -62,6 +62,15 @@ const ListPage = () => { getLocation() }, []); + // 监听距离和排序方式变化,自动调用接口 + useEffect(() => { + // 只有当 distanceQuickFilter 有值时才调用接口 + if (distanceQuickFilter?.distance !== undefined || distanceQuickFilter?.quick !== undefined) { + console.log('距离或排序方式发生变化,重新获取数据:', distanceQuickFilter); + getMatchesData(); + } + }, [distanceQuickFilter?.distance, distanceQuickFilter?.quick]); + // 获取位置信息 const getLocation = async () => { const location = await getCurrentLocationInfo() diff --git a/src/store/listStore.ts b/src/store/listStore.ts index 840ff74..c7f3896 100644 --- a/src/store/listStore.ts +++ b/src/store/listStore.ts @@ -154,7 +154,7 @@ export const useListStore = create()((set, get) => ({ }, // 获取列表数据(常规搜索) - fetchMatches: async (params) => { + fetchMatches: async (params, isFirstLoad = false) => { set({ loading: true, error: null }); const { getSearchParams, setListData, distanceQuickFilter } = get(); @@ -172,6 +172,11 @@ export const useListStore = create()((set, get) => ({ if (isIntegrate) { reqParams.order = ""; fetchFn = getGamesIntegrateList; + + // 第一次进入页面时传入 isRefresh 参数 + if (isFirstLoad) { + reqParams.isRefresh = true; + } } console.log("===fetchMatches 获取列表数据参数:", reqParams); @@ -187,7 +192,6 @@ export const useListStore = create()((set, get) => ({ } const { count, rows } = data; setListData({ - // recommendList: rows || [], error: '', data: rows || [], loading: false, @@ -246,12 +250,7 @@ export const useListStore = create()((set, get) => ({ // 获取列表数据 getMatchesData: () => { const { fetchMatches } = get(); - fetchMatches(); - // if (distanceQuickFilter?.quick === "0") { - // getIntegrateListData(); - // } else { - // fetchMatches(); - // } + fetchMatches({}, true); // 第一次进入页面,传入 isFirstLoad = true }, // 获取历史搜索数据 diff --git a/types/list/types.ts b/types/list/types.ts index 63e6787..ede3572 100644 --- a/types/list/types.ts +++ b/types/list/types.ts @@ -61,7 +61,7 @@ export interface ListState { } export interface ListActions { - fetchMatches: (params?: Record) => Promise + fetchMatches: (params?: Record,isFirstLoad?: Boolean) => Promise // getIntegrateListData: (params?: Record) => Promise getMatchesData: () => void clearError: () => void