feat(shop): 添加文章详情页面并优化购物车样式

- 新增文章详情页面组件,用于显示文章内容
- 优化购物车页面样式,增加空购物车状态的透明背景
- 添加多个购物相关 API 接口,包括优惠券、订单等
- 更新环境配置,修改 API 基础 URL
- 调整发现页面布局,增加文章详情入口
This commit is contained in:
2025-08-13 01:37:07 +08:00
parent 1802a27234
commit 1c2e00b7ba
21 changed files with 1072 additions and 179 deletions

View File

@@ -13,6 +13,7 @@ import {
import {ArrowLeft, Del, Shopping} from '@nutui/icons-react-taro';
import {View} from '@tarojs/components';
import {CartItem, useCart} from "@/hooks/useCart";
import './cart.scss';
function Cart() {
const [statusBarHeight, setStatusBarHeight] = useState<number>(0);
@@ -69,6 +70,21 @@ function Cart() {
});
}, []);
// 根据购物车状态动态设置页面背景色
useEffect(() => {
if (cartItems.length === 0) {
// 购物车为空时设置透明背景
Taro.setBackgroundColor({
backgroundColor: 'transparent'
});
} else {
// 有商品时恢复默认背景
Taro.setBackgroundColor({
backgroundColor: '#f5f5f5'
});
}
}, [cartItems.length]);
// 处理单个商品选择
const handleItemSelect = (goodsId: number, checked: boolean) => {
if (checked) {
@@ -184,7 +200,10 @@ function Cart() {
<Empty
description="购物车空空如也"
actions={[{ text: '去逛逛' }]}
style={{ marginTop: `${statusBarHeight + 50}px` }}
style={{
marginTop: `${statusBarHeight + 50}px`,
backgroundColor: 'transparent'
}}
onClick={() => Taro.switchTab({ url: '/pages/index/index' })}
/>
</>
@@ -226,13 +245,20 @@ function Cart() {
</NavBar>
{/* 购物车内容 */}
<View className="pt-24">
<View
className="pt-24"
style={{ backgroundColor: cartItems.length === 0 ? 'transparent' : undefined }}
>
{cartItems.length === 0 ? (
// 空购物车
<View className="flex flex-col items-center justify-center h-96">
<View
className="cart-empty-container flex flex-col items-center justify-center h-96"
style={{ backgroundColor: 'transparent' }}
>
<Empty
image={<Shopping size={80}/>}
description="购物车空空如也"
style={{ backgroundColor: 'transparent' }}
>
<Button
type="primary"