From 70af5426e8b700b2c789d80bce783980643c3e57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Tue, 14 Jul 2026 02:31:49 +0800 Subject: [PATCH] =?UTF-8?q?feat(shop):=20=E6=B7=BB=E5=8A=A0=E5=95=86?= =?UTF-8?q?=E5=9F=8E=E5=88=97=E8=A1=A8=E9=A1=B5=E6=B5=AE=E5=8A=A8=E8=B4=AD?= =?UTF-8?q?=E7=89=A9=E8=BD=A6=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 shop 页面右下角添加固定定位的绿色圆形购物车按钮 - 按钮右上角显示购物车商品数量角标,超过 99 显示为 99+ - 点击按钮跳转到购物车页面,非 tabBar 页面 - 使用 useCartContext 的 totalCount 实时更新商品数量显示 - 注释掉用户页面 “我的钱包” 入口,暂时隐藏该功能 --- .workbuddy/memory/2026-07-14.md | 13 ++++++++++ src/pages/shop/index.tsx | 43 ++++++++++++++++++++++++++++++++- src/pages/user/index.tsx | 2 +- 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/.workbuddy/memory/2026-07-14.md b/.workbuddy/memory/2026-07-14.md index eb2587e..fdedb2c 100644 --- a/.workbuddy/memory/2026-07-14.md +++ b/.workbuddy/memory/2026-07-14.md @@ -147,6 +147,19 @@ adapter `/list` 接口忽略分页,一次返回全部收藏;前端 `listShop 3. `useEffect` 中增加 `if (!user?.userId) return` 判断,已登录但 userId 还没拿到时等待下次渲染 4. `useEffect` 依赖数组加 `user?.userId`,userId 变化时重新触发加载 +## 商城列表页浮动购物车按钮(2026-07-14) + +### 需求 +`pages/shop/index` 页面右下角添加浮动购物车按钮,显示购物车商品数量角标。 + +### 实现 +- **`src/pages/shop/index.tsx`**: + 1. 从 `useCartContext()` 额外解构 `totalCount` + 2. 页面末尾添加 fixed 定位浮动按钮:绿色圆形(48px),`bottom:80px right:16px`(避开 tabBar) + 3. `totalCount > 0` 时右上角显示红色角标,超过 99 显示 `99+` + 4. 点击 `Taro.navigateTo` 跳转购物车页(cart 非 tabBar 页) + 5. 数量实时更新:`addItem` 内部调 `refresh()` → `totalCount` 派生值自动重渲染 + ## 购物车页面进入不刷新 Bug 修复(2026-07-14) ### 问题 diff --git a/src/pages/shop/index.tsx b/src/pages/shop/index.tsx index f713f11..0c9f712 100644 --- a/src/pages/shop/index.tsx +++ b/src/pages/shop/index.tsx @@ -36,7 +36,7 @@ const SORT_TABS: { key: SortKey; label: string }[] = [ ] const ShopPage: React.FC = () => { - const { addItem } = useCartContext() + const { addItem, totalCount } = useCartContext() const [categoryList, setCategoryList] = useState(PRESET_CATEGORIES) const [activeCategory, setActiveCategory] = useState(0) @@ -343,6 +343,47 @@ const ShopPage: React.FC = () => { + + {/* 浮动购物车按钮 */} + Taro.navigateTo({ url: '/pages/shop/cart' })} + > + 🛒 + {totalCount > 0 && ( + + + {totalCount > 99 ? '99+' : totalCount} + + + )} + ) } diff --git a/src/pages/user/index.tsx b/src/pages/user/index.tsx index fdc1b7d..00c315f 100644 --- a/src/pages/user/index.tsx +++ b/src/pages/user/index.tsx @@ -23,7 +23,7 @@ const UserPage: React.FC = () => { { icon: '📅', label: '预约订单', url: '/pages/booking/list' }, { icon: '🏆', label: '赛事活动', url: '/pages/event/my/index' }, { icon: '🎫', label: '优惠券', url: '/pages/user/coupon-list' }, - { icon: '💰', label: '我的钱包', url: '/pages/user/wallet' }, + // { icon: '💰', label: '我的钱包', url: '/pages/user/wallet' }, { icon: '📍', label: '收货地址', url: '/pages/user/address-list' }, { icon: '⭐', label: '积分明细', url: '/pages/user/points-record' }, { icon: '🔔', label: '消息通知', url: '/pages/index/notification' },