首页定位问题
This commit is contained in:
@@ -8,8 +8,9 @@ import RegionPicker from '../components/RegionPicker';
|
||||
import {
|
||||
DEFAULT_REGION,
|
||||
FALLBACK_CITY_REGION,
|
||||
formatRegion,
|
||||
formatRegionCity,
|
||||
REGION_ALL,
|
||||
toCityLevelRegion,
|
||||
type RegionSelection,
|
||||
} from '../lib/region-data';
|
||||
import { FALLBACK_CITY_CODE, resolveUserCity } from '../lib/wechat-location';
|
||||
@@ -62,7 +63,7 @@ export default function StoreListPage() {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [categoryTab, setCategoryTab] = useState<string>('全部');
|
||||
const [keyword, setKeyword] = useState('');
|
||||
const [region, setRegion] = useState<RegionSelection>(DEFAULT_REGION);
|
||||
const [region, setRegion] = useState<RegionSelection>(() => toCityLevelRegion(DEFAULT_REGION));
|
||||
const [regionPickerOpen, setRegionPickerOpen] = useState(false);
|
||||
const [filterMode, setFilterMode] = useState<'auto' | 'manual'>('auto');
|
||||
const [usedFallback, setUsedFallback] = useState(false);
|
||||
@@ -82,7 +83,7 @@ export default function StoreListPage() {
|
||||
if (filterMode !== 'auto' || geoReady) return;
|
||||
resolveUserCity().then((resolved) => {
|
||||
if (resolved) {
|
||||
setRegion(resolved.region);
|
||||
setRegion(toCityLevelRegion(resolved.region));
|
||||
}
|
||||
setGeoReady(true);
|
||||
});
|
||||
@@ -103,7 +104,7 @@ export default function StoreListPage() {
|
||||
code !== FALLBACK_CITY_CODE
|
||||
) {
|
||||
setUsedFallback(true);
|
||||
setRegion(FALLBACK_CITY_REGION);
|
||||
setRegion(toCityLevelRegion(FALLBACK_CITY_REGION));
|
||||
return null;
|
||||
}
|
||||
return data;
|
||||
@@ -138,11 +139,8 @@ export default function StoreListPage() {
|
||||
const city = s.cityName ?? '郑州市';
|
||||
if (region.province !== REGION_ALL && province !== region.province) return false;
|
||||
if (region.city !== REGION_ALL && city !== region.city) return false;
|
||||
if (region.district !== REGION_ALL && s.district !== region.district) return false;
|
||||
return true;
|
||||
});
|
||||
} else if (region.district !== REGION_ALL) {
|
||||
list = list.filter((s) => s.district === region.district);
|
||||
}
|
||||
const q = keyword.trim().toLowerCase();
|
||||
if (q) {
|
||||
@@ -156,7 +154,7 @@ export default function StoreListPage() {
|
||||
return list;
|
||||
}, [stores, categoryTab, keyword, region, cityCode]);
|
||||
|
||||
const regionLabel = formatRegion(region.province, region.city, region.district);
|
||||
const regionLabel = formatRegionCity(region.province, region.city);
|
||||
const emptyMessage =
|
||||
filterMode === 'manual' && filtered.length === 0
|
||||
? '未找到匹配门店'
|
||||
@@ -271,10 +269,11 @@ export default function StoreListPage() {
|
||||
<RegionPicker
|
||||
open={regionPickerOpen}
|
||||
value={region}
|
||||
levels={2}
|
||||
onClose={() => setRegionPickerOpen(false)}
|
||||
onConfirm={(next) => {
|
||||
setFilterMode('manual');
|
||||
setRegion(next);
|
||||
setRegion(toCityLevelRegion(next));
|
||||
setRegionPickerOpen(false);
|
||||
}}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user