1
This commit is contained in:
@@ -17,7 +17,6 @@ import {
|
||||
ListState,
|
||||
IPayload,
|
||||
} from "../../types/list/types";
|
||||
import { useUser } from "./userStore";
|
||||
|
||||
function translateCityData(dataTree) {
|
||||
return dataTree.map((item) => {
|
||||
@@ -185,7 +184,8 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
||||
gamesNum: 0,
|
||||
|
||||
// 组装搜索数据
|
||||
getSearchParams: (overrideArea?: [string, string]) => {
|
||||
// 注意:始终使用 state.area,不接收 overrideArea 参数,确保参数一致性
|
||||
getSearchParams: () => {
|
||||
const state = get();
|
||||
const currentPageState = state.isSearchResult ? state.searchPageState : state.listPageState;
|
||||
const filterOptions = currentPageState?.filterOptions || {};
|
||||
@@ -193,12 +193,9 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
||||
const distanceQuickFilter = currentPageState?.distanceQuickFilter || {};
|
||||
const { distanceFilter, order, district } = distanceQuickFilter || {};
|
||||
|
||||
// 优先使用 overrideArea(切换城市时传入),其次使用 area 状态
|
||||
// area 会在 userLastLocationProvince 更新时自动同步,所以这里直接使用 area 即可
|
||||
const areaProvince = overrideArea?.at(1) || state.area?.at(1) || "";
|
||||
const userInfo = useUser.getState().user as any;
|
||||
// 始终使用 state.area,确保所有接口使用一致的城市参数
|
||||
const areaProvince = state.area?.at(1) || "";
|
||||
const last_location_province = areaProvince;
|
||||
const last_location_city = userInfo?.last_location_city || "";
|
||||
|
||||
// city 参数逻辑:
|
||||
// 1. 如果选择了行政区(district 有值),使用行政区的名称(label)
|
||||
@@ -216,6 +213,8 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
||||
// 使用 filterOptions 中的 dateRange
|
||||
const dateRange: [string, string] = filterOptions?.dateRange || defaultDateRange;
|
||||
|
||||
// 构建 searchOption
|
||||
// 注意:province 必须从 state.area 获取,不能依赖 filterOptions 中可能存在的旧值
|
||||
const searchOption: any = {
|
||||
...filterOptions,
|
||||
title: state.searchValue,
|
||||
@@ -223,7 +222,8 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
||||
ntrpMax: filterOptions?.ntrp?.[1],
|
||||
dateRange: dateRange, // 确保始终是两个值的数组
|
||||
distanceFilter: distanceFilter,
|
||||
province: last_location_province, // 使用 province 替代 last_location_province
|
||||
// 显式设置 province,确保始终使用 state.area 中的最新值
|
||||
province: last_location_province, // 始终使用 state.area 中的 province,确保城市参数一致
|
||||
};
|
||||
|
||||
// 只在有值时添加 city 参数
|
||||
@@ -336,13 +336,14 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
||||
},
|
||||
|
||||
// 同时更新两个列表接口(常规列表和智能排序列表)
|
||||
refreshBothLists: async (overrideArea?: [string, string]) => {
|
||||
// 注意:不再接收 overrideArea 参数,始终使用 state.area
|
||||
refreshBothLists: async () => {
|
||||
const state = get();
|
||||
const { getSearchParams, setListData } = state;
|
||||
const { getGamesList, getGamesIntegrateList } = await import("../services/listApi");
|
||||
|
||||
try {
|
||||
const searchParams = getSearchParams(overrideArea) || {};
|
||||
const searchParams = getSearchParams() || {};
|
||||
|
||||
// 调用常规列表接口
|
||||
const listParams = {
|
||||
@@ -407,11 +408,24 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
||||
},
|
||||
|
||||
// 获取球局数量
|
||||
fetchGetGamesCount: async (overrideArea?: [string, string]) => {
|
||||
// 注意:必须和 games/integrate_list 使用相同的参数构建逻辑,确保数据一致性
|
||||
// 不再接收 overrideArea 参数,始终使用 state.area
|
||||
fetchGetGamesCount: async () => {
|
||||
const state = get();
|
||||
const { getSearchParams } = state;
|
||||
const params = getSearchParams(overrideArea) || {};
|
||||
console.log("fetchGetGamesCount 参数:", { overrideArea, params: JSON.stringify(params) });
|
||||
const searchParams = getSearchParams() || {};
|
||||
|
||||
// 使用和 games/integrate_list 相同的参数构建逻辑
|
||||
const params = {
|
||||
...searchParams,
|
||||
order: "", // 和 integrate_list 保持一致
|
||||
seachOption: {
|
||||
...searchParams.seachOption,
|
||||
isRefresh: true, // 和 integrate_list 保持一致
|
||||
},
|
||||
};
|
||||
|
||||
console.log("fetchGetGamesCount 参数:", { area: state.area, params: JSON.stringify(params) });
|
||||
const resData = (await getGamesCount(params)) || {};
|
||||
const gamesNum = resData?.data?.count || 0;
|
||||
console.log("fetchGetGamesCount 结果:", gamesNum);
|
||||
@@ -527,10 +541,13 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
||||
});
|
||||
|
||||
// 使用 Promise.resolve 确保状态更新后再调用接口
|
||||
Promise.resolve().then(() => {
|
||||
// 先调用列表接口,然后在列表接口完成后调用数量接口
|
||||
Promise.resolve().then(async () => {
|
||||
const freshState = get(); // 重新获取最新状态
|
||||
// 传入当前的 area,确保接口请求的地址与界面显示一致
|
||||
freshState.fetchGetGamesCount(freshState.area);
|
||||
// 先调用列表接口
|
||||
await freshState.getMatchesData();
|
||||
// 列表接口完成后,再调用数量接口
|
||||
await freshState.fetchGetGamesCount();
|
||||
});
|
||||
},
|
||||
|
||||
@@ -548,16 +565,18 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
||||
});
|
||||
|
||||
// 使用 Promise.resolve 确保状态更新后再调用接口
|
||||
Promise.resolve().then(() => {
|
||||
// 先调用列表接口,然后在列表接口完成后调用数量接口
|
||||
Promise.resolve().then(async () => {
|
||||
const freshState = get(); // 重新获取最新状态
|
||||
freshState.getMatchesData();
|
||||
// 传入当前的 area,确保接口请求的地址与界面显示一致
|
||||
freshState.fetchGetGamesCount(freshState.area);
|
||||
// 先调用列表接口
|
||||
await freshState.getMatchesData();
|
||||
// 列表接口完成后,再调用数量接口
|
||||
await freshState.fetchGetGamesCount();
|
||||
});
|
||||
},
|
||||
|
||||
// 清空综合筛选选项
|
||||
clearFilterOptions: () => {
|
||||
clearFilterOptions: async () => {
|
||||
const state = get();
|
||||
const { getMatchesData, fetchGetGamesCount } = state;
|
||||
|
||||
@@ -566,8 +585,10 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
||||
filterCount: 0,
|
||||
pageOption: defaultPageOption,
|
||||
});
|
||||
getMatchesData();
|
||||
fetchGetGamesCount();
|
||||
// 先调用列表接口
|
||||
await getMatchesData();
|
||||
// 列表接口完成后,再调用数量接口
|
||||
await fetchGetGamesCount();
|
||||
},
|
||||
|
||||
// 加载更多数据
|
||||
@@ -616,8 +637,10 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
||||
if (!isSearchData) {
|
||||
return;
|
||||
}
|
||||
await fetchGetGamesCount();
|
||||
// 先调用列表接口
|
||||
await getMatchesData();
|
||||
// 列表接口完成后,再调用数量接口
|
||||
await fetchGetGamesCount();
|
||||
},
|
||||
|
||||
// 更新store数据
|
||||
|
||||
Reference in New Issue
Block a user