diff --git a/src/api/shop/shopGoods/model/index.ts b/src/api/shop/shopGoods/model/index.ts index ce4328f..39e372e 100644 --- a/src/api/shop/shopGoods/model/index.ts +++ b/src/api/shop/shopGoods/model/index.ts @@ -146,4 +146,5 @@ export interface ShopGoodsParam extends PageParam { isShow?: number; stock?: number; keywords?: string; + recommend?: number; } diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index 1fa973a..2c36ff5 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -7,11 +7,11 @@ import { Cart, Coupon, Gift, Ticket } from '@nutui/icons-react-taro' import { getShopInfo } from '@/api/layout' import { checkAndHandleInviteRelation, hasPendingInvite } from '@/utils/invite' import { pageShopGoods } from '@/api/shop/shopGoods' -import type { ShopGoods } from '@/api/shop/shopGoods/model' +import type { ShopGoods, ShopGoodsParam } from '@/api/shop/shopGoods/model' import './index.scss' function Home() { - const [activeTab, setActiveTab] = useState('推荐') + const [activeTabKey, setActiveTabKey] = useState('recommend') const [goodsList, setGoodsList] = useState([]) useShareAppMessage(() => { @@ -96,10 +96,6 @@ function Home() { }) - pageShopGoods({}).then(res => { - setGoodsList(res?.list || []) - }) - // 检查是否有待处理的邀请关系 - 异步处理,不阻塞页面加载 if (hasPendingInvite()) { console.log('检测到待处理的邀请关系') @@ -153,7 +149,30 @@ function Home() { }); }, []); - const tabs = useMemo(() => ['推荐', '桶装水', '优惠组合', '购机套餐', '饮水设备'], []) + const tabs = useMemo< + Array<{ key: string; title: string; params: Partial }> + >( + () => [ + { key: 'recommend', title: '推荐', params: { recommend: 1 } }, + { key: '4476', title: '桶装水', params: { categoryId: 4476 } }, + { key: '4556', title: '优惠组合', params: { categoryId: 4556 } }, + { key: '4557', title: '购机套餐', params: { categoryId: 4557 } }, + { key: '4477', title: '饮水设备', params: { categoryId: 4477 } }, + ], + [] + ) + + useEffect(() => { + const tab = tabs.find((t) => t.key === activeTabKey) || tabs[0] + if (!tab) return + + pageShopGoods({ ...tab.params }) + .then((res) => setGoodsList(res?.list || [])) + .catch((err) => { + console.error('首页商品列表加载失败:', err) + setGoodsList([]) + }) + }, [activeTabKey, tabs]) const shortcuts = useMemo< Array<{ key: string; title: string; icon: ReactNode; onClick: () => void }> @@ -169,7 +188,7 @@ function Home() { key: 'order', title: '立即订水', icon: , - onClick: () => Taro.navigateTo({ url: '/shop/goodsDetail/index?id=10072' }), + onClick: () => Taro.navigateTo({ url: '/shop/goodsDetail/index?id=10074' }), }, { key: 'invite', @@ -232,14 +251,14 @@ function Home() { {tabs.map((tab) => { - const active = tab === activeTab + const active = tab.key === activeTabKey return ( setActiveTab(tab)} + onClick={() => setActiveTabKey(tab.key)} > - {tab} + {tab.title} ) })} diff --git a/src/shop/gift/index.config.ts b/src/shop/gift/index.config.ts new file mode 100644 index 0000000..3dcbab8 --- /dev/null +++ b/src/shop/gift/index.config.ts @@ -0,0 +1,4 @@ +export default definePageConfig({ + navigationBarTitleText: '立即订水', + navigationBarTextStyle: 'black' +}) diff --git a/src/shop/gift/index.tsx b/src/shop/gift/index.tsx new file mode 100644 index 0000000..e69de29