diff --git a/apps/h5-user/src/pages/HomePage.tsx b/apps/h5-user/src/pages/HomePage.tsx index 0905d06..7c49df4 100644 --- a/apps/h5-user/src/pages/HomePage.tsx +++ b/apps/h5-user/src/pages/HomePage.tsx @@ -11,6 +11,7 @@ import { FALLBACK_CITY_CODE, resolveUserCity, } from '../lib/wechat-location'; +import { formatRegionCity } from '../lib/region-data'; import CouponBadge from '@dukang/shared-ui/CouponBadge'; type Product = { @@ -44,8 +45,7 @@ export default function HomePage() { const [products, setProducts] = useState([]); const [cities, setCities] = useState([]); const [cityCode, setCityCode] = useState(() => localStorage.getItem(CITY_STORAGE_KEY) || FALLBACK_CITY_CODE); - const [locatedCityLabel, setLocatedCityLabel] = useState(''); - const [citySource, setCitySource] = useState<'auto' | 'manual'>('auto'); + const [locationLabel, setLocationLabel] = useState('定位中...'); const [toast, setToast] = useState(''); useEffect(() => { @@ -62,10 +62,13 @@ export default function HomePage() { }, []); useEffect(() => { - if (citySource !== 'auto') return; resolveUserCity().then((resolved) => { - if (!resolved) return; - setLocatedCityLabel(resolved.displayCity); + if (!resolved) { + setLocationLabel('郑州市'); + setCityCode(FALLBACK_CITY_CODE); + return; + } + setLocationLabel(formatRegionCity(resolved.province, resolved.city)); if (resolved.openCity && resolved.cityCode) { setCityCode(resolved.cityCode); } else { @@ -74,7 +77,7 @@ export default function HomePage() { window.setTimeout(() => setToast(''), 2200); } }); - }, [citySource]); + }, []); useEffect(() => { if (!cityCode) return; @@ -95,8 +98,6 @@ export default function HomePage() { setTab(key); } - const selectedCity = cities.find((c) => c.code === cityCode); - const headerCityLabel = locatedCityLabel || selectedCity?.name || '郑州市'; const filtered = products.filter((p) => p.aromaType === tab); const onSale = tab === 'QINGXIANG'; @@ -105,23 +106,9 @@ export default function HomePage() { - location_on - {headerCityLabel} - +
+ location_on + {locationLabel}
)} /> diff --git a/apps/h5-user/src/styles.css b/apps/h5-user/src/styles.css index 05eec1c..7c68771 100644 --- a/apps/h5-user/src/styles.css +++ b/apps/h5-user/src/styles.css @@ -606,21 +606,16 @@ max-width: 46vw; } +.tab-main-city--readonly { + pointer-events: none; + user-select: none; +} + .tab-main-city-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; - max-width: 72px; -} - -.tab-main-city-select { - border: none; - background: transparent; - font: inherit; - color: inherit; - max-width: 72px; - opacity: 0.85; - font-size: 11px; + max-width: 120px; } .tab-main-city .material-symbols-outlined {