1
This commit is contained in:
@@ -214,6 +214,38 @@ const ListPageContent: React.FC<ListPageContentProps> = ({
|
||||
}
|
||||
}, [isActive]);
|
||||
|
||||
// 记录上一次的城市,用于检测城市变化
|
||||
const prevAreaRef = useRef<[string, string] | null>(null);
|
||||
|
||||
// 监听城市变化,重新获取行政区列表并清空已选择的行政区
|
||||
useEffect(() => {
|
||||
if (area && area.length >= 2) {
|
||||
const currentProvince = area[1];
|
||||
const prevProvince = prevAreaRef.current?.[1];
|
||||
|
||||
// 只有当城市真正改变时才执行(避免初始化时也触发)
|
||||
if (prevProvince && prevProvince !== currentProvince) {
|
||||
console.log("城市改变,重新获取行政区列表:", {
|
||||
prevProvince,
|
||||
currentProvince,
|
||||
});
|
||||
// 城市改变时,重新获取行政区列表
|
||||
getDistricts();
|
||||
// 清空已选择的行政区,避免显示错误的行政区
|
||||
const currentState = useListStore.getState();
|
||||
const currentPageState = currentState.isSearchResult
|
||||
? currentState.searchPageState
|
||||
: currentState.listPageState;
|
||||
if (currentPageState?.distanceQuickFilter?.district) {
|
||||
updateDistanceQuickFilter({ district: undefined });
|
||||
}
|
||||
}
|
||||
// 更新记录的城市
|
||||
prevAreaRef.current = area as [string, string];
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [area?.[1]]); // 只监听省份(area[1])的变化
|
||||
|
||||
// 当页面从非激活状态切换为激活状态时,检查城市是否变化,如果变化则重新加载数据
|
||||
useEffect(() => {
|
||||
// 如果从非激活状态变为激活状态(切回列表页)
|
||||
|
||||
Reference in New Issue
Block a user