小程序修改

This commit is contained in:
2026-07-12 19:44:36 +08:00
parent 3b4833b51a
commit e2dfb08de3
45 changed files with 2028 additions and 347 deletions
+27 -7
View File
@@ -4,13 +4,23 @@ import Taro, { useDidShow } from '@tarojs/taro';
import PageShell from '../../components/PageShell';
import TabMainHeader from '../../components/TabMainHeader';
import RegionPicker from '../../components/RegionPicker';
import {
DEFAULT_REGION,
formatRegionLabel,
matchesRegionFilter,
type RegionSelection,
} from '../../lib/region-data';
import UserTabBar, { shouldRenderPageTabBar, syncTabBarSelected } from '../../components/UserTabBar';
import { getCityCodeForCatalog, resolveUserCity } from '../../lib/user-location';
import { FALLBACK_CITY_CODE } from '../../lib/product-images';
import { request, toast } from '../../lib/api';
type Store = {
id: string;
name: string;
address?: string;
province?: string;
cityName?: string;
district?: string;
coverUrl?: string | null;
openTime?: string | null;
@@ -26,21 +36,30 @@ export default function StoresPage() {
const [loading, setLoading] = useState(true);
const [categoryTab, setCategoryTab] = useState<string>('全部');
const [keyword, setKeyword] = useState('');
const [regionLabel, setRegionLabel] = useState('郑州市 · 全部区域');
const [region, setRegion] = useState<RegionSelection>(DEFAULT_REGION);
const [regionOpen, setRegionOpen] = useState(false);
const [cityCode, setCityCode] = useState<string>(FALLBACK_CITY_CODE);
const regionLabel = formatRegionLabel(region);
useDidShow(() => {
syncTabBarSelected(1);
void resolveUserCity().then((resolved) => {
setRegion(resolved.region);
setCityCode(getCityCodeForCatalog(resolved));
});
});
useEffect(() => {
request<Store[]>('/stores')
setLoading(true);
const path = cityCode ? `/stores?cityCode=${encodeURIComponent(cityCode)}` : '/stores';
request<Store[]>(path)
.then((list) => setStores(Array.isArray(list) ? list : []))
.catch((e) => toast(e instanceof Error ? e.message : '加载失败'))
.finally(() => setLoading(false));
}, []);
}, [cityCode]);
const filtered = stores.filter((s) => {
if (!matchesRegionFilter(s, region)) return false;
if (!keyword.trim()) return true;
const q = keyword.trim();
return s.name.includes(q) || (s.address ?? '').includes(q) || (s.district ?? '').includes(q);
@@ -59,11 +78,11 @@ export default function StoresPage() {
<View className="store-toolbar">
<View className="store-location" onClick={() => setRegionOpen(true)}>
<View className="store-location-pin" />
<Text>{regionLabel} </Text>
<Text className="store-location-text">{regionLabel} </Text>
</View>
<Input
className="store-search"
placeholder="搜索门店名称或地址"
placeholder="搜索门店"
value={keyword}
onInput={(e) => setKeyword(e.detail.value)}
/>
@@ -123,9 +142,10 @@ export default function StoresPage() {
{shouldRenderPageTabBar() ? <UserTabBar selected={1} /> : null}
<RegionPicker
open={regionOpen}
valueLabel="郑州市"
value={region}
levels={3}
onClose={() => setRegionOpen(false)}
onConfirm={(label) => setRegionLabel(`${label} · 全部区域`)}
onConfirm={(next) => setRegion(next)}
/>
</PageShell>
);