This commit is contained in:
张成
2025-12-07 00:04:02 +08:00
parent 80dc582963
commit 82b6b6f80e
3 changed files with 37 additions and 23 deletions

View File

@@ -243,11 +243,24 @@ const HomeNavbar = (props: IProps) => {
// 处理城市切换(用户手动选择)
const handleCityChange = async (_newArea: any) => {
// 用户手动选择的城市不保存到缓存
// 用户手动选择的城市不保存到缓存(临时切换)
console.log("用户手动选择城市(不保存缓存):", _newArea);
// 切换城市后,同时更新两个列表接口获取数据
await handleCityChangeWithoutCache();
// 先更新 area 状态(用于界面显示)
updateArea(_newArea);
// 确保状态更新完成后再调用接口
// 切换城市后,同时更新两个列表接口获取数据,传入新的城市信息
const promises: Promise<any>[] = [];
if (refreshBothLists) {
promises.push(refreshBothLists(_newArea));
}
// 更新球局数量,直接传入新的城市信息,不依赖状态更新时序
if (fetchGetGamesCount) {
promises.push(fetchGetGamesCount(_newArea));
}
// 并行执行,提高性能
await Promise.all(promises);
};
return (

View File

@@ -185,7 +185,7 @@ export const useListStore = create<TennisStore>()((set, get) => ({
gamesNum: 0,
// 组装搜索数据
getSearchParams: () => {
getSearchParams: (overrideArea?: [string, string]) => {
const state = get();
const currentPageState = state.isSearchResult ? state.searchPageState : state.listPageState;
const filterOptions = currentPageState?.filterOptions || {};
@@ -193,9 +193,12 @@ export const useListStore = create<TennisStore>()((set, get) => ({
const distanceQuickFilter = currentPageState?.distanceQuickFilter || {};
const { distanceFilter, order, district } = distanceQuickFilter || {};
// 从用户信息中获取 last_location_province 和 last_location_city
// 优先使用 overrideArea切换城市时传入其次使用 area 状态中的省份,最后使用用户信息中的
const areaProvince = overrideArea?.at(1) || state.area?.at(1) || "";
const userInfo = useUser.getState().user as any;
const last_location_province = userInfo?.last_location_province || "";
const userLastLocationProvince = userInfo?.last_location_province || "";
// 优先使用切换后的城市,如果没有切换过则使用用户信息中的
const last_location_province = areaProvince || userLastLocationProvince;
const last_location_city = userInfo?.last_location_city || "";
// city 参数逻辑:
@@ -221,15 +224,12 @@ export const useListStore = create<TennisStore>()((set, get) => ({
ntrpMax: filterOptions?.ntrp?.[1],
dateRange: dateRange, // 确保始终是两个值的数组
distanceFilter: distanceFilter,
last_location_province: last_location_province, // 使用 last_location_province
province: last_location_province, // 使用 province 替代 last_location_province
};
// 只在有值时添加 city 参数(使用 last_location_city
// 只在有值时添加 city 参数
if (city) {
searchOption.last_location_city = city;
} else if (last_location_city) {
// 如果没有选择行政区,但有 last_location_city则使用它
searchOption.last_location_city = last_location_city;
searchOption.city = city;
}
const params = {
@@ -337,13 +337,13 @@ export const useListStore = create<TennisStore>()((set, get) => ({
},
// 同时更新两个列表接口(常规列表和智能排序列表)
refreshBothLists: async () => {
refreshBothLists: async (overrideArea?: [string, string]) => {
const state = get();
const { getSearchParams, setListData } = state;
const { getGamesList, getGamesIntegrateList } = await import("../services/listApi");
try {
const searchParams = getSearchParams() || {};
const searchParams = getSearchParams(overrideArea) || {};
// 调用常规列表接口
const listParams = {
@@ -408,11 +408,14 @@ export const useListStore = create<TennisStore>()((set, get) => ({
},
// 获取球局数量
fetchGetGamesCount: async () => {
const { getSearchParams } = get();
const params = getSearchParams() || {};
fetchGetGamesCount: async (overrideArea?: [string, string]) => {
const state = get();
const { getSearchParams } = state;
const params = getSearchParams(overrideArea) || {};
console.log("fetchGetGamesCount 参数:", { overrideArea, params: JSON.stringify(params) });
const resData = (await getGamesCount(params)) || {};
const gamesNum = resData?.data?.count || 0;
console.log("fetchGetGamesCount 结果:", gamesNum);
set({ gamesNum });
},
@@ -695,9 +698,7 @@ export const useListStore = create<TennisStore>()((set, get) => ({
},
updateArea(payload: [string, string]) {
const state = get();
set({
...state,
area: payload,
})
},

View File

@@ -111,11 +111,11 @@ export interface ListActions {
getSearchHistory: () => Promise<void>;
clearHistory: () => void;
searchSuggestion: (val: string) => Promise<void>;
getSearchParams: () => Record<string, any>;
getSearchParams: (overrideArea?: [string, string]) => Record<string, any>;
loadMoreMatches: () => Promise<void>;
initialFilterSearch: (isSearchData?: boolean) => void;
setListData: (payload: IPayload) => void;
fetchGetGamesCount: () => Promise<void>;
fetchGetGamesCount: (overrideArea?: [string, string]) => Promise<void>;
getCurrentPageState: () => { currentPageState: any; currentPageKey: string };
updateCurrentPageState: (payload: Record<string, any>) => void;
updateDistanceQuickFilter: (payload: Record<string, any>) => void;
@@ -123,7 +123,7 @@ export interface ListActions {
getCityQrCode: () => Promise<void>;
getDistricts: () => Promise<BubbleOption[]>; // 新增:获取行政区
updateArea: (payload: [string, string]) => void;
refreshBothLists: () => Promise<void>;
refreshBothLists: (overrideArea?: [string, string]) => Promise<void>;
}
export interface IPayload {