This commit is contained in:
liu
2026-08-21 12:41:15 +08:00
parent 8a7bdca6b1
commit 4bbe92d8e8
6 changed files with 50 additions and 13 deletions
+18 -4
View File
@@ -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() {
{/* ========== 头部 ========== */}
<View className='cart-header'>
<Text className='cart-header__title'></Text>
{items.length > 0 && (
{loggedIn && items.length > 0 && (
<Text className='cart-header__clear' onClick={handleClear}></Text>
)}
</View>
{/* ========== 列表 ========== */}
{items.length === 0 ? (
{!loggedIn ? (
<Empty description='登录后查看购物车' className='cart-empty'>
<View className='cart-empty__btn' onClick={goLogin}></View>
</Empty>
) : items.length === 0 ? (
loading ? (
<View className='cart-loading'><Text>...</Text></View>
) : (
@@ -238,14 +252,14 @@ export default function CartPage() {
))
)}
{hasInvalid && (
{loggedIn && hasInvalid && (
<View className='cart-invalid-hint'>
<Text></Text>
</View>
)}
{/* ========== 底部结算栏 ========== */}
{items.length > 0 && (
{loggedIn && items.length > 0 && (
<View className='cart-footer'>
<View className='cart-footer__total'>
<Text className='cart-footer__label'>{totalQuantity}</Text>