From d38baa9c5bcd1994df9c27a7dae4a9bf10f94f53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=88=90?= Date: Wed, 10 Sep 2025 11:11:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8E=A5=E5=8F=A3=20?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3=20=E7=AC=AC=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/list/index.tsx | 9 +++++++++ src/store/listStore.ts | 15 +++++++-------- types/list/types.ts | 2 +- 3 files changed, 17 insertions(+), 9 deletions(-) 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