添加接口 列表接口 第一次更新逻辑
This commit is contained in:
@@ -62,6 +62,15 @@ const ListPage = () => {
|
|||||||
getLocation()
|
getLocation()
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// 监听距离和排序方式变化,自动调用接口
|
||||||
|
useEffect(() => {
|
||||||
|
// 只有当 distanceQuickFilter 有值时才调用接口
|
||||||
|
if (distanceQuickFilter?.distance !== undefined || distanceQuickFilter?.quick !== undefined) {
|
||||||
|
console.log('距离或排序方式发生变化,重新获取数据:', distanceQuickFilter);
|
||||||
|
getMatchesData();
|
||||||
|
}
|
||||||
|
}, [distanceQuickFilter?.distance, distanceQuickFilter?.quick]);
|
||||||
|
|
||||||
// 获取位置信息
|
// 获取位置信息
|
||||||
const getLocation = async () => {
|
const getLocation = async () => {
|
||||||
const location = await getCurrentLocationInfo()
|
const location = await getCurrentLocationInfo()
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 获取列表数据(常规搜索)
|
// 获取列表数据(常规搜索)
|
||||||
fetchMatches: async (params) => {
|
fetchMatches: async (params, isFirstLoad = false) => {
|
||||||
set({ loading: true, error: null });
|
set({ loading: true, error: null });
|
||||||
const { getSearchParams, setListData, distanceQuickFilter } = get();
|
const { getSearchParams, setListData, distanceQuickFilter } = get();
|
||||||
|
|
||||||
@@ -172,6 +172,11 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
|||||||
if (isIntegrate) {
|
if (isIntegrate) {
|
||||||
reqParams.order = "";
|
reqParams.order = "";
|
||||||
fetchFn = getGamesIntegrateList;
|
fetchFn = getGamesIntegrateList;
|
||||||
|
|
||||||
|
// 第一次进入页面时传入 isRefresh 参数
|
||||||
|
if (isFirstLoad) {
|
||||||
|
reqParams.isRefresh = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("===fetchMatches 获取列表数据参数:", reqParams);
|
console.log("===fetchMatches 获取列表数据参数:", reqParams);
|
||||||
@@ -187,7 +192,6 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
|||||||
}
|
}
|
||||||
const { count, rows } = data;
|
const { count, rows } = data;
|
||||||
setListData({
|
setListData({
|
||||||
// recommendList: rows || [],
|
|
||||||
error: '',
|
error: '',
|
||||||
data: rows || [],
|
data: rows || [],
|
||||||
loading: false,
|
loading: false,
|
||||||
@@ -246,12 +250,7 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
|||||||
// 获取列表数据
|
// 获取列表数据
|
||||||
getMatchesData: () => {
|
getMatchesData: () => {
|
||||||
const { fetchMatches } = get();
|
const { fetchMatches } = get();
|
||||||
fetchMatches();
|
fetchMatches({}, true); // 第一次进入页面,传入 isFirstLoad = true
|
||||||
// if (distanceQuickFilter?.quick === "0") {
|
|
||||||
// getIntegrateListData();
|
|
||||||
// } else {
|
|
||||||
// fetchMatches();
|
|
||||||
// }
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// 获取历史搜索数据
|
// 获取历史搜索数据
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ export interface ListState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ListActions {
|
export interface ListActions {
|
||||||
fetchMatches: (params?: Record<string, any>) => Promise<void>
|
fetchMatches: (params?: Record<string, any>,isFirstLoad?: Boolean) => Promise<void>
|
||||||
// getIntegrateListData: (params?: Record<string, any>) => Promise<void>
|
// getIntegrateListData: (params?: Record<string, any>) => Promise<void>
|
||||||
getMatchesData: () => void
|
getMatchesData: () => void
|
||||||
clearError: () => void
|
clearError: () => void
|
||||||
|
|||||||
Reference in New Issue
Block a user