diff --git a/project.config.json b/project.config.json index adba2c3..673ff6f 100644 --- a/project.config.json +++ b/project.config.json @@ -2,7 +2,7 @@ "miniprogramRoot": "./", "projectname": "pure-project-vantui", "description": "", - "appid": "wx7ed74d60503b5ee3", + "appid": "wx8f48874e3bf1dccd", "setting": { "urlCheck": false, "es6": true, diff --git a/src/pages/cart/index.less b/src/pages/cart/index.less index f26b6ec..bde7197 100644 --- a/src/pages/cart/index.less +++ b/src/pages/cart/index.less @@ -24,6 +24,15 @@ .cart-empty { padding-top: 160rpx; + + &__btn { + margin-top: 24rpx; + padding: 14rpx 60rpx; + background: #ee0a24; + color: #fff; + font-size: 28rpx; + border-radius: 999rpx; + } } .cart-loading { diff --git a/src/pages/cart/index.tsx b/src/pages/cart/index.tsx index c5b6ba3..32ee4d0 100644 --- a/src/pages/cart/index.tsx +++ b/src/pages/cart/index.tsx @@ -2,6 +2,7 @@ import { useCallback, useEffect, useRef, useState } from 'react' import Taro, { useDidShow } from '@tarojs/taro' import { View, Text, Image, Textarea, ScrollView } from '@tarojs/components' import { Button, Empty, Icon, Popup, Stepper } from '@antmjs/vantui' +import useAuthStore from '@/stores/auth/useAuthStore' import useCartStore from '@/stores/cart/useCartStore' import { createOrderApi } from '@/services/order' import { getStoreInfoApi } from '@/services/store' @@ -12,6 +13,7 @@ import type { StoreDetail } from '@/types/store' import './index.less' export default function CartPage() { + const token = useAuthStore(s => s.token) const items = useCartStore(s => s.items) const totalQuantity = useCartStore(s => s.totalQuantity) const totalAmount = useCartStore(s => s.totalAmount) @@ -39,6 +41,12 @@ export default function CartPage() { const purchasable = items.filter(item => item.status === 1) const hasInvalid = items.length > 0 && purchasable.length < items.length + const loggedIn = !!token + + const goLogin = useCallback(() => { + Taro.navigateTo({ url: '/pages/login/index' }) + }, []) + /** 拉取门店配送信息 */ const fetchStoreInfo = useCallback(() => { setStoreLoading(true) @@ -49,6 +57,8 @@ export default function CartPage() { }, []) useDidShow(() => { + // 未登录不请求接口,直接展示去登录空态(参考消息页) + if (!loggedIn) return fetchCart().catch(() => {}) // 从门店信息编辑页返回且弹层仍打开时 → 刷新配送信息 if (showOrder) fetchStoreInfo() @@ -177,13 +187,17 @@ export default function CartPage() { {/* ========== 头部 ========== */} 购物车 - {items.length > 0 && ( + {loggedIn && items.length > 0 && ( 清空 )} {/* ========== 列表 ========== */} - {items.length === 0 ? ( + {!loggedIn ? ( + + 去登录 + + ) : items.length === 0 ? ( loading ? ( 加载中... ) : ( @@ -238,14 +252,14 @@ export default function CartPage() { )) )} - {hasInvalid && ( + {loggedIn && hasInvalid && ( 部分商品已下架或未设置您所在等级的价格,不可下单 )} {/* ========== 底部结算栏 ========== */} - {items.length > 0 && ( + {loggedIn && items.length > 0 && ( 合计(可购{totalQuantity}件) diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index 48aa728..e443d73 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -102,6 +102,11 @@ export default function IndexPage() { Taro.switchTab({ url: '/pages/product/index' }) }, []) + /** 跳转商品详情 */ + const goDetail = useCallback((id: number) => { + Taro.navigateTo({ url: `/pages/product-detail/index?id=${id}` }) + }, []) + /** 搜索框聚焦/提交 → 商品页搜索 */ const handleSearchFocus = useCallback(() => { goProduct(keyword.trim()) @@ -240,7 +245,7 @@ export default function IndexPage() { ) : ( {products.map(product => ( - goProduct()}> + goDetail(product.id)}> { + /** 右侧列表触底加载(页面为固定布局不滚动,由 ScrollView 触发) */ + const handleLoadMore = useCallback(() => { if (!finished) { fetchList(page + 1, false) } - }) + }, [finished, page, fetchList]) /** 点击一级分类:有子分类仅展开/收起(不可选中),无子分类则选中 */ const handleTopTap = useCallback((cat: Category) => { @@ -274,8 +275,13 @@ export default function ProductPage() { })} - {/* ========== 右侧商品列表 ========== */} - + {/* ========== 右侧商品列表(ScrollView 滚动 + 触底加载) ========== */} + {/* 商品列表 */} {products.length === 0 && !loading ? ( @@ -317,7 +323,7 @@ export default function ProductPage() { {finished && products.length > 0 && ( 没有更多了 )} - + {/* ========== 加购弹层 ========== */}