Quellcode durchsuchen

♻️ refactor(goods-detail): 优化商品详情页逻辑与代码风格

- 使用 Boolean() 函数明确转换 hasSpecOptions 变量类型
- 移除开发调试用的 console.warn 日志输出
- 改进数量输入框的边界检查逻辑,将 `quantity === 0` 改为 `quantity < 1`
- 清理已注释的调试代码,保持代码整洁
- 调整代码格式,移除多余空行并添加必要分隔
yourname vor 1 Monat
Ursprung
Commit
763602591f
1 geänderte Dateien mit 5 neuen und 6 gelöschten Zeilen
  1. 5 6
      mini/src/pages/goods-detail/index.tsx

+ 5 - 6
mini/src/pages/goods-detail/index.tsx

@@ -125,7 +125,8 @@ export default function GoodsDetailPage() {
     staleTime: 5 * 60 * 1000,
   })
 
-  const hasSpecOptions = childGoodsData && childGoodsData.data && childGoodsData.data.length > 0
+  const hasSpecOptions = Boolean(childGoodsData && childGoodsData.data && childGoodsData.data.length > 0)
+
 
   // 商品轮播图
   const carouselItems = goods?.slideImages?.map((file: any) => ({
@@ -143,7 +144,6 @@ export default function GoodsDetailPage() {
 
     // 如果显示价格与API价格不一致,记录警告
     if (displayedPrice !== apiPrice) {
-      console.warn('价格显示不一致:', { displayedPrice, apiPrice, goodsId: goods.id })
       // 在实际项目中可以发送错误报告或显示用户提示
     }
   }
@@ -249,8 +249,8 @@ export default function GoodsDetailPage() {
 
   // 处理输入框失去焦点(完成输入)
   const handleQuantityBlur = () => {
-    // 如果数量为0(表示空输入),设为1
-    if (quantity === 0) {
+    // 如果数量小于1(表示空输入或负数),设为1
+    if (quantity < 1) {
       setQuantity(1)
     }
   }
@@ -342,8 +342,6 @@ export default function GoodsDetailPage() {
       totalAmount: targetPrice * finalQuantity
     })
 
-    // const buyNowData = Taro.getStorageSync('buyNow')
-    // console.log("buyNowbefore:",buyNowData)
 
     Taro.navigateTo({
       url: '/pages/order-submit/index'
@@ -498,6 +496,7 @@ export default function GoodsDetailPage() {
           </View>
         </View>
 
+
         <View className="button-section">
           <Button
             className="add-cart-btn"