import { useEffect, useState } from 'react'; import { Link } from 'react-router-dom'; import { request } from '../lib/api'; import ProductCarousel from '../components/ProductCarousel'; import TabMainHeader from '../components/TabMainHeader'; import AppToast from '../components/AppToast'; import { getProductImages } from '../lib/product-images'; import CouponBadge from '@dukang/shared-ui/CouponBadge'; type Product = { id: string; name: string; subtitle: string; price: number; benefitDisplay: number; mainImageUrl: string; carouselUrls?: string[] | null; aromaType: string; status: string; }; const AROMA_TABS = [ { key: 'QINGXIANG', label: '清香型', open: true }, { key: 'JIANGXIANG', label: '酱香型', open: false }, { key: 'NONGXIANG', label: '浓香型', open: false }, ]; export default function HomePage() { const [tab, setTab] = useState('QINGXIANG'); const [products, setProducts] = useState([]); const [toast, setToast] = useState(''); useEffect(() => { request('USER_H5', '/catalog/products').then(setProducts); }, []); function showToast(message: string) { setToast(message); window.setTimeout(() => setToast(''), 2200); } function onAromaTabClick(key: string, open: boolean) { if (!open) { showToast('暂未开放'); return; } setTab(key); } const filtered = products.filter((p) => p.aromaType === tab); const onSale = tab === 'QINGXIANG'; return (
location_on 郑州市
)} />
{!onSale &&
该香型暂未上线,敬请期待
} {onSale && filtered.map((p, index) => (

{p.name}

¥{p.price}

{p.subtitle}

立即购买
))}
); }