This commit is contained in:
张成
2026-02-06 00:26:31 +08:00
parent 969066591c
commit d149de1f42
9 changed files with 91 additions and 73 deletions

View File

@@ -36,14 +36,17 @@ export const useDictionaryStore = create<DictionaryState>()((set, get) => ({
set({ isLoading: true, error: null })
try {
const keys = 'publishing_requirements,court_type,court_surface,supplementary_information,game_play,fabu_tip';
const keys = 'publishing_requirements,court_type,court_surface,supplementary_information,game_play,fabu_tip,supported_cities';
const response = await commonApi.getDictionaryManyKey(keys)
if (response.code === 0 && response.data) {
const dictionaryData = {};
keys.split(',').forEach(key => {
const list = response.data[key];
const listData = list.split('|');
// supported_cities 格式如 "上海市||北京市",用 || 分割
const listData = key === 'supported_cities'
? (list ? String(list).split('||').map((s) => s.trim()).filter(Boolean) : [])
: (list ? list.split('|') : []);
dictionaryData[key] = listData;
})
set({

View File

@@ -44,16 +44,16 @@ function translateCityData(dataTree) {
return dataTree.map((item) => {
const { children, ...rest } = item;
// 只保留两级:国家和省份,去掉第三级(区域)
const processedChildren = children?.length > 0
const processedChildren = children?.length > 0
? children.map(child => ({
...child,
text: child.name,
label: child.name,
value: child.name,
children: null, // 去掉第三级
}))
...child,
text: child.name,
label: child.name,
value: child.name,
children: null, // 去掉第三级
}))
: null;
return {
...rest,
text: rest.name,
@@ -214,20 +214,19 @@ export const useListStore = create<TennisStore>()((set, get) => ({
// 全城和快捷筛选
const distanceQuickFilter = currentPageState?.distanceQuickFilter || {};
const { distanceFilter, order, district } = distanceQuickFilter || {};
// 始终使用 state.area确保所有接口使用一致的城市参数
const areaProvince = state.area?.at(1) || "";
const areaProvince = state.area?.at(0) || "";
const areaCity = state.area?.at(1) || "";
const last_location_province = areaProvince;
// city 参数逻辑:
// 1. 如果选择了行政区district 有值使用行政区的名称label
// 2. 如果是"全城"distanceFilter 为空),不传 city
let city: string | undefined = undefined;
let county: string | undefined = undefined;
if (district) {
// 从 districts 数组中查找对应的行政区名称
const selectedDistrict = state.districts.find(item => item.value === district);
if (selectedDistrict) {
city = selectedDistrict.label; // 传递行政区名称,如"静安"
county = selectedDistrict.label; // 传递行政区名称,如"静安"
}
}
// 如果是"全城"distanceFilter 为空city 保持 undefined不会被传递
@@ -246,12 +245,13 @@ export const useListStore = create<TennisStore>()((set, get) => ({
distanceFilter: distanceFilter,
// 显式设置 province确保始终使用 state.area 中的最新值
province: last_location_province, // 始终使用 state.area 中的 province确保城市参数一致
city: areaCity,
};
// 只在有值时添加 city 参数
if (city) {
searchOption.city = city;
}
if (county) {
searchOption.county = county;
}
const params = {
pageOption: currentPageState?.pageOption,
@@ -374,7 +374,7 @@ export const useListStore = create<TennisStore>()((set, get) => ({
try {
const searchParams = getSearchParams() || {};
// 并发请求:常规列表、智能排序列表
const [listResSettled, integrateResSettled] = await Promise.allSettled([
getGamesList({
@@ -447,7 +447,7 @@ export const useListStore = create<TennisStore>()((set, get) => ({
const state = get();
const { getSearchParams } = state;
const searchParams = getSearchParams() || {};
// 使用和 games/integrate_list 相同的参数构建逻辑
const params = {
...searchParams,
@@ -457,7 +457,7 @@ export const useListStore = create<TennisStore>()((set, get) => ({
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;
@@ -551,7 +551,7 @@ export const useListStore = create<TennisStore>()((set, get) => ({
const state = get();
const { currentPageState } = state.getCurrentPageState();
const filterOptions = { ...currentPageState?.filterOptions, ...payload };
// 计算筛选数量:排除 dateRange、ntrp 默认值,以及空数组和空字符串
const filterCount = Object.entries(filterOptions).filter(([key, value]) => {
if (key === 'dateRange') return false; // 日期区间不算筛选
@@ -572,7 +572,7 @@ export const useListStore = create<TennisStore>()((set, get) => ({
filterCount,
pageOption: defaultPageOption,
});
// 使用 Promise.resolve 确保状态更新后再调用接口
// 先调用列表接口,然后在列表接口完成后调用数量接口
Promise.resolve().then(async () => {
@@ -590,7 +590,7 @@ export const useListStore = create<TennisStore>()((set, get) => ({
const { currentPageState } = state.getCurrentPageState();
const { distanceQuickFilter } = currentPageState || {};
const newDistanceQuickFilter = { ...distanceQuickFilter, ...payload };
// 先更新状态
state.updateCurrentPageState({
distanceQuickFilter: newDistanceQuickFilter,
@@ -729,15 +729,15 @@ export const useListStore = create<TennisStore>()((set, get) => ({
async getDistricts() {
try {
const state = get();
// 从 area 中获取省份area 格式: ["中国", 省份, 城市]
const country = "中国";
// 从 area 中获取省份area 格式: [ 省份, 城市]
const province = state.area?.at(0) || "上海";
const cn_city = state.area?.at(1) || "上海市"; // area[1] 是省份
const res = await getDistricts({
country,
state: cn_city
const res = await getDistricts({
province,
city: cn_city
});
if (res.code === 0 && res.data) {
const districts = res.data.map((item) => ({
label: item.cn_county,

View File

@@ -48,10 +48,10 @@ export const useUser = create<UserState>()((set) => ({
// 优先使用缓存中的城市,不使用用户信息中的位置
// 检查是否有缓存的城市
const cachedCity = (Taro as any).getStorageSync?.(CITY_CACHE_KEY);
if (cachedCity && Array.isArray(cachedCity) && cachedCity.length === 2) {
// 如果有缓存的城市,使用缓存,不更新 area
@@ -63,10 +63,10 @@ export const useUser = create<UserState>()((set) => ({
if (userData?.last_location_province) {
const listStore = useListStore.getState();
const currentArea = listStore.area;
// 只有当 area 不存在时才使用用户信息中的位置
if (!currentArea) {
const newArea: [string, string] = ["中国", userData.last_location_province];
const newArea: [string, string] = [userData.last_location_province||"", userData.last_location_city||""];
listStore.updateArea(newArea);
// 保存到缓存
useUser.getState().updateCache(newArea);
@@ -103,7 +103,7 @@ export const useUser = create<UserState>()((set) => ({
const currentArea = listStore.area;
// 只有当 area 不存在或与 userLastLocationProvince 不一致时才更新
if (!currentArea || currentArea[1] !== userInfo.last_location_province) {
const newArea: [string, string] = ["中国", userInfo.last_location_province];
const newArea: [string, string] = [userInfo.last_location_province || "", userInfo.last_location_city || ""];
listStore.updateArea(newArea);
}
}