Files
template-10584/src/components/CartIcon.tsx
赵忠林 1e51a137ee refactor(components): 重构 CouponCard 组件样式
- 优化了 CouponCard 组件的视觉效果,增加了更多细节和动画
- 添加了响应式样式,提高了移动端体验
- 新增了 CouponList组件样式,用于展示优惠券列表
2025-08-22 17:27:45 +08:00

61 lines
1.2 KiB
TypeScript

import React from 'react';
import { Badge } from "@nutui/nutui-react-taro";
import { Cart } from "@nutui/icons-react-taro";
import { useCart } from "@/hooks/useCart";
import { switchTab } from '@/utils/navigation';
interface CartIconProps {
style?: React.CSSProperties;
className?: string;
size?: number;
showBadge?: boolean;
onClick?: () => void;
}
const CartIcon: React.FC<CartIconProps> = ({
style,
className = '',
size = 16,
showBadge = true,
onClick
}) => {
const { cartCount } = useCart();
const handleClick = () => {
if (onClick) {
onClick();
} else {
// 默认跳转到购物车页面
switchTab('cart/cart');
}
};
if (showBadge) {
return (
<div
className={className}
style={style}
onClick={handleClick}
>
<Badge value={cartCount} top="-2" right="2">
<div style={{ display: 'flex', alignItems: 'center' }}>
<Cart size={size} />
</div>
</Badge>
</div>
);
}
return (
<div
className={className}
style={style}
onClick={handleClick}
>
<Cart size={size} />
</div>
);
};
export default CartIcon;