diff --git a/.workbuddy/memory/2026-07-14.md b/.workbuddy/memory/2026-07-14.md index d9d256e..e2fbef7 100644 --- a/.workbuddy/memory/2026-07-14.md +++ b/.workbuddy/memory/2026-07-14.md @@ -202,5 +202,20 @@ adapter `/list` 接口忽略分页,一次返回全部收藏;前端 `listShop 2. 导出 base64 数据 URI 常量:`src/assets/icons/index.ts` 中 `CART_ICON_WHITE` 3. `src/pages/shop/index.tsx` 浮动购物车按钮改用 `Image` 组件加载 `CART_ICON_WHITE`(28×28px,`mode='aspectFit'`),图标更清晰 -### 备注 -商品详情页底部操作栏的购物车入口仍使用 emoji `🛒`,若需统一风格可同步替换。 +## 商品详情页出现孤立 "0" 排查修复(2026-07-14) + +### 问题 +`pages/shop/product-detail` 价格区域下方出现一个不归属任何标签的孤立 `0`。 + +### 根因 +`src/pages/shop/product-detail.tsx` 中赚取积分行的条件渲染写成: +```tsx +{product.gainIntegral && Number(product.gainIntegral) > 0 && (...)} +``` +当后端返回 `gainIntegral` 为数字 `0` 时,JSX 短路与运算直接返回 `0`,React 会把它渲染成一个纯文本节点。这就是页面上那个孤立的 `0`。 + +### 修改 +- **`src/pages/shop/product-detail.tsx`**: + - 去掉条件里的 `product.gainIntegral &&`,改成 `{Number(product.gainIntegral) > 0 && (...)}`,避免 `0` 泄漏。 + - 顺手把配送区域 `goodsWeight` 的同类写法也改成 `{Number(product.goodsWeight) > 0 && (...)}`,防止重量为 0 时同样泄漏。 + - 另按用户要求「是 0 就不显示」,把销量行也改为 `{Number(product.sales) > 0 && (...)}`,销量为 0 时整条「销量: 0」不渲染。 diff --git a/src/pages/shop/category.tsx b/src/pages/shop/category.tsx index 40c7394..80b6fbb 100644 --- a/src/pages/shop/category.tsx +++ b/src/pages/shop/category.tsx @@ -262,7 +262,7 @@ const CategoryPage: React.FC = () => { {/* 加购按钮 */} handleAddToCart(e, item)} > + diff --git a/src/pages/shop/product-detail.tsx b/src/pages/shop/product-detail.tsx index 5ba9687..58d42d4 100644 --- a/src/pages/shop/product-detail.tsx +++ b/src/pages/shop/product-detail.tsx @@ -309,13 +309,15 @@ const ProductDetailPage: React.FC = () => { )} {/* 赚取积分 */} - {product.gainIntegral && Number(product.gainIntegral) > 0 && ( + {Number(product.gainIntegral) > 0 && ( 购买可得 {product.gainIntegral} 积分 )} - 销量: {product.sales || 0} + {Number(product.sales) > 0 && ( + 销量: {product.sales} + )} 库存: {product.stock || 0} {product.unitName && ( 单位: {product.unitName} @@ -363,7 +365,7 @@ const ProductDetailPage: React.FC = () => { 配送 {deliveryText} - {product.goodsWeight && Number(product.goodsWeight) > 0 && ( + {Number(product.goodsWeight) > 0 && ( 重量: {product.goodsWeight}kg )}