fix(shop): 修复商品详情页孤立“0”渲染问题
- 修正赚取积分、重量和销量条件渲染,避免数字0被渲染成文本节点 - 赚取积分判断改为仅判断数值是否大于0,防止0泄漏 - 重量同样改为判断数值大于0避免显示无效数据 - 销量为0时隐藏销量信息,符合用户需求 - 调整加购按钮尺寸,使其视觉更协调
This commit is contained in:
@@ -325,7 +325,7 @@ const ShopPage: React.FC = () => {
|
||||
</View>
|
||||
{/* 加购按钮 */}
|
||||
<View
|
||||
className='w-7 h-7 rounded-full bg-green-500 flex items-center justify-center flex-shrink-0 ml-1'
|
||||
className='w-6 h-6 rounded-full bg-green-500 flex items-center justify-center flex-shrink-0 ml-1'
|
||||
onClick={(e) => handleAddToCart(e, item)}
|
||||
>
|
||||
<Text className='text-white text-lg leading-none'>+</Text>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React, { useState, useEffect, useRef } from 'react'
|
||||
import { View, Text, Image, ScrollView, Swiper, SwiperItem, RichText } from '@tarojs/components'
|
||||
import { Tag } from '@nutui/nutui-react-taro'
|
||||
import Taro, { useRouter } from '@tarojs/taro'
|
||||
import Taro, { useRouter, useDidShow } from '@tarojs/taro'
|
||||
import { getShopGoods } from '@/api/shop/shopGoods'
|
||||
import {
|
||||
addShopGoodsFavorite,
|
||||
@@ -34,7 +34,7 @@ const ProductDetailPage: React.FC = () => {
|
||||
const [skuVisible, setSkuVisible] = useState(false)
|
||||
const [skuMode, setSkuMode] = useState<'cart' | 'buy'>('cart')
|
||||
const [isFavorite, setIsFavorite] = useState(false)
|
||||
const { addItem } = useCartContext()
|
||||
const { addItem, totalCount, refresh } = useCartContext()
|
||||
const { isLoggedIn } = useUserContext()
|
||||
// 底部操作栏高度约 90px(含按钮 + 安全区),动态计算 ScrollView 可用高度
|
||||
const scrollHeight = useScrollHeight(44)
|
||||
@@ -58,6 +58,11 @@ const ProductDetailPage: React.FC = () => {
|
||||
}
|
||||
}, [id, isLoggedIn])
|
||||
|
||||
// 页面显示时刷新购物车数量,确保底部购物车角标准确
|
||||
useDidShow(() => {
|
||||
if (isLoggedIn) refresh()
|
||||
})
|
||||
|
||||
// 监听 product 变化后再添加到历史记录,并异步生成分享海报
|
||||
useEffect(() => {
|
||||
if (product) {
|
||||
@@ -422,7 +427,31 @@ const ProductDetailPage: React.FC = () => {
|
||||
{/* 图标入口 */}
|
||||
<View className='flex items-center px-2 py-2' style={{ minWidth: '120px' }}>
|
||||
<View className='flex-1 flex flex-col items-center' onClick={handleGoCart}>
|
||||
<Text className='text-lg'>🛒</Text>
|
||||
<View className='relative inline-flex items-center justify-center'>
|
||||
<Text className='text-lg'>🛒</Text>
|
||||
{totalCount > 0 && (
|
||||
<View
|
||||
className='flex items-center justify-center'
|
||||
style={{
|
||||
position: 'absolute',
|
||||
top: '-6px',
|
||||
right: '-10px',
|
||||
minWidth: '16px',
|
||||
height: '16px',
|
||||
borderRadius: '8px',
|
||||
backgroundColor: '#ef4444',
|
||||
borderWidth: '1.5px',
|
||||
borderStyle: 'solid',
|
||||
borderColor: '#ffffff',
|
||||
paddingHorizontal: '3px',
|
||||
}}
|
||||
>
|
||||
<Text className='text-white text-[10px] font-bold leading-none'>
|
||||
{totalCount > 99 ? '99+' : totalCount}
|
||||
</Text>
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
<Text className='text-xs text-gray-500 mt-1 whitespace-nowrap'>购物车</Text>
|
||||
</View>
|
||||
<View className='flex-1 flex flex-col items-center' onClick={handleContactService}>
|
||||
|
||||
Reference in New Issue
Block a user