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

@@ -149,3 +149,7 @@ src/
## License
MIT
"appid": "wx915ecf6c01bea4ec",
"appid": "wx815b533167eb7b53",

View File

@@ -2,7 +2,8 @@
"miniprogramRoot": "dist/",
"projectname": "playBallTogether",
"description": "playBallTogether",
"appid": "wx915ecf6c01bea4ec",
"appid": "wx815b533167eb7b53",
"setting": {
"urlCheck": true,
"es6": true,

View File

@@ -116,7 +116,7 @@ const DistanceQuickFilterV2 = (props) => {
// 延时一下
await new Promise(resolve => setTimeout(resolve, 600));
// 先清除缓存和 area确保使用最新的用户信息
await updateCache( ["中国", response.data.last_location_province]);
await updateCache( [ response.data.last_location_province, response.data.last_location_city ]);
}

View File

@@ -105,9 +105,9 @@ const HomeNavbar = (props: IProps) => {
const userInfo = useUserInfo();
// 使用用户详情接口中的 last_location 字段
// USER_SELECTED_CITY 第二个值应该是省份/直辖市,不能是区
const lastLocationProvince = (userInfo as any)?.last_location_province || "";
const lastLocationCity = (userInfo as any)?.last_location_city || "";
// 只使用省份/直辖市,不使用城市(城市可能是区)
const detectedLocation = lastLocationProvince;
const detectedLocation = lastLocationCity;
// 检查是否应该显示定位确认弹窗
const should_show_location_dialog = (): boolean => {
@@ -192,7 +192,7 @@ const HomeNavbar = (props: IProps) => {
} else if (detectedLocation) {
// 只有在完全没有缓存的情况下,才使用用户详情中的位置信息
console.log("[HomeNavbar] 没有缓存,使用用户详情中的位置信息:", detectedLocation);
const newArea: [string, string] = ["中国", detectedLocation];
const newArea: [string, string] = [(userInfo as any)?.last_location_province || "", detectedLocation];
updateArea(newArea);
// 保存定位信息到缓存
(Taro as any).setStorageSync(CITY_CACHE_KEY, newArea);
@@ -266,7 +266,7 @@ const HomeNavbar = (props: IProps) => {
const { detectedProvince } = locationDialogData;
// 用户选择"切换到",使用用户详情中的位置信息
const newArea: [string, string] = ["中国", detectedProvince];
const newArea: [string, string] = [(userInfo as any)?.last_location_province || "", detectedProvince];
updateArea(newArea);
// 更新缓存为新的定位信息
(Taro as any).setStorageSync(CITY_CACHE_KEY, newArea);
@@ -481,8 +481,7 @@ const HomeNavbar = (props: IProps) => {
{/* 搜索导航 */}
{!showTitle && (
<View
className={`inputCustomerNavbarContainer toggleElement secondElement hidden ${
showInput && "visible"
className={`inputCustomerNavbarContainer toggleElement secondElement hidden ${showInput && "visible"
} ${showInput ? "inputCustomerNavbarShowInput" : ""}`}
style={navbarStyle}
>

View File

@@ -66,6 +66,8 @@ const ListPageContent: React.FC<ListPageContentProps> = ({
gamesNum, // 新增:获取球局数量
} = store;
const supportedCitiesList = useDictionaryStore((s) => s.getDictionaryValue('supported_cities', ['上海市'])) || [];
const {
isShowFilterPopup,
data: matches,
@@ -92,6 +94,8 @@ const ListPageContent: React.FC<ListPageContentProps> = ({
// 记录上一次加载数据时的城市,用于检测城市变化
const lastLoadedAreaRef = useRef<[string, string] | null>(null);
const prevIsActiveRef = useRef(isActive);
// 记录是否是进入列表页的第一次调用 updateUserLocation首次传 force: true
const hasUpdatedLocationRef = useRef(false);
// 处理距离筛选显示/隐藏
const handleDistanceFilterVisibleChange = useCallback(
@@ -364,7 +368,10 @@ const ListPageContent: React.FC<ListPageContentProps> = ({
updateState({ location });
if (location && location.latitude && location.longitude) {
try {
await updateUserLocation(location.latitude, location.longitude);
// 进入列表页的第一次调用传 force: true后续调用传 false
const isFirstCall = !hasUpdatedLocationRef.current;
await updateUserLocation(location.latitude, location.longitude, isFirstCall);
hasUpdatedLocationRef.current = true;
} catch (error) {
console.error("更新用户位置失败:", error);
}
@@ -476,7 +483,7 @@ const ListPageContent: React.FC<ListPageContentProps> = ({
initDictionaryData();
}, []);
// 获取省份名称area 格式: ["中国", "省份"]
const province = area?.at(1) || "上海";
function renderCityQrcode() {
@@ -518,8 +525,12 @@ const ListPageContent: React.FC<ListPageContentProps> = ({
}
// 判定是否显示"暂无球局"页面
// 条件:省份不是上海 或 (已加载完成且球局数量为0)
const shouldShowNoGames = province !== "上海市";
// 从配置接口 /parameter/many_key 获取 supported_cities格式如 "上海市||北京市"
// 当前省份在有球局城市列表中则显示列表,否则显示暂无球局
const shouldShowNoGames =
supportedCitiesList.length > 0
? !supportedCitiesList.includes(province)
: province !== "上海市"; // 配置未加载时默认按上海判断
return (
<>

View File

@@ -134,7 +134,7 @@ export const getCityQrCode = async () => {
}
// 获取行政区列表
export const getDistricts = async (params: { country: string; state: string }) => {
export const getDistricts = async (params: { province: string; city: string }) => {
try {
// 调用HTTP服务获取行政区列表
return httpService.post('/cities/cities', params)

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

@@ -216,18 +216,17 @@ export const useListStore = create<TennisStore>()((set, get) => ({
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,11 +245,12 @@ 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 = {
@@ -729,13 +729,13 @@ 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
province,
city: cn_city
});
if (res.code === 0 && res.data) {

View File

@@ -66,7 +66,7 @@ export const useUser = create<UserState>()((set) => ({
// 只有当 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);
}
}