This commit is contained in:
张成
2025-12-08 15:56:56 +08:00
parent a8dca0dd71
commit 0dd0b711f9
7 changed files with 103 additions and 58 deletions

View File

@@ -180,6 +180,11 @@ const HomeNavbar = (props: IProps) => {
// const currentAddress = city + district;
const handleInputClick = () => {
// 关闭城市选择器
if (cityPopupVisible) {
setCityPopupVisible(false);
}
const currentPagePath = getCurrentFullPath();
if (currentPagePath === "/game_pages/searchResult/index") {
(Taro as any).navigateBack();
@@ -192,6 +197,11 @@ const HomeNavbar = (props: IProps) => {
// 点击logo
const handleLogoClick = () => {
// 关闭城市选择器
if (cityPopupVisible) {
setCityPopupVisible(false);
}
// 如果当前在列表页,点击后页面回到顶部
if (getCurrentFullPath() === "/main_pages/index") {
// 使用父组件传递的滚动方法(适配 ScrollView
@@ -212,6 +222,11 @@ const HomeNavbar = (props: IProps) => {
};
const handleInputLeftIconClick = () => {
// 关闭城市选择器
if (cityPopupVisible) {
setCityPopupVisible(false);
}
if (leftIconClick) {
leftIconClick();
} else {
@@ -231,13 +246,13 @@ const HomeNavbar = (props: IProps) => {
// 处理城市切换(仅刷新数据,不保存缓存)
const handleCityChangeWithoutCache = async () => {
// 切换城市后,同时更新两个列表接口获取数据,传入当前的 area
// 先调用列表接口
if (refreshBothLists) {
await refreshBothLists(area);
await refreshBothLists();
}
// 更新球局数量,传入当前的 area确保接口请求的地址与界面显示一致
// 列表接口完成后,再调用数量接口
if (fetchGetGamesCount) {
await fetchGetGamesCount(area);
await fetchGetGamesCount();
}
};
@@ -246,21 +261,17 @@ const HomeNavbar = (props: IProps) => {
// 用户手动选择的城市不保存到缓存(临时切换)
console.log("用户手动选择城市(不保存缓存):", _newArea);
// 先更新 area 状态(用于界面显示)
// 先更新 area 状态(用于界面显示和接口参数
updateArea(_newArea);
// 确保状态更新完成后再调用接口
// 切换城市后,同时更新两个列表接口获取数据,传入新的城市信息
const promises: Promise<any>[] = [];
// 先调用列表接口(会使用更新后的 state.area
if (refreshBothLists) {
promises.push(refreshBothLists(_newArea));
await refreshBothLists();
}
// 更新球局数量,直接传入新的城市信息,不依赖状态更新时序
// 列表接口完成后,再调用数量接口(会使用更新后的 state.area
if (fetchGetGamesCount) {
promises.push(fetchGetGamesCount(_newArea));
await fetchGetGamesCount();
}
// 并行执行,提高性能
await Promise.all(promises);
};
return (