Procházet zdrojové kódy

♻️ refactor(goods): 统一商品卡片点击事件处理逻辑

- 移除GoodsCard组件的onThumbClick属性及相关处理函数
- 删除GoodsList组件中对应的onThumbClick属性传递
- 注释掉未使用的isValidityLinePrice变量
- 商品图片区域点击事件统一由卡片根元素处理
yourname před 1 měsícem
rodič
revize
7112454ac5

+ 7 - 8
mini/src/components/goods-card/index.tsx

@@ -16,7 +16,6 @@ interface GoodsCardProps {
   data: GoodsData
   currency?: string
   onClick?: (goods: GoodsData) => void
-  onThumbClick?: (goods: GoodsData) => void
   onAddCart?: (goods: GoodsData) => void
 }
 
@@ -25,7 +24,6 @@ export default function GoodsCard({
   data,
   currency = '¥',
   onClick,
-  onThumbClick,
   onAddCart
 }: GoodsCardProps) {
   const independentID = id || `goods-card-${Math.floor(Math.random() * 10 ** 8)}`
@@ -34,10 +32,11 @@ export default function GoodsCard({
     onClick?.(data)
   }
 
-  const handleThumbClick = (e: any) => {
-    e.stopPropagation()
-    onThumbClick?.(data)
-  }
+  // 移除单独的图片点击事件,改为整个卡片统一处理
+  // const handleThumbClick = (e: any) => {
+  //   e.stopPropagation()
+  //   onThumbClick?.(data)
+  // }
 
   const handleAddCart = (e: any) => {
     e.stopPropagation()
@@ -49,7 +48,7 @@ export default function GoodsCard({
     return price.toFixed(2)
   }
 
-  const isValidityLinePrice = data.originPrice && data.price && data.originPrice >= data.price
+  // const isValidityLinePrice = data.originPrice && data.price && data.originPrice >= data.price
 
   return (
     <View
@@ -60,7 +59,7 @@ export default function GoodsCard({
     >
       <View className="goods-card__main">
         {/* 商品图片 */}
-        <View className="goods-card__thumb" onClick={handleThumbClick}>
+        <View className="goods-card__thumb">
           {data.cover_image && (
             <Image
               src={data.cover_image}

+ 1 - 7
mini/src/components/goods-list/index.tsx

@@ -8,7 +8,6 @@ export interface GoodsListProps {
   thresholds?: any[]
   onClick?: (goods: GoodsData, index: number) => void
   onAddCart?: (goods: GoodsData, index: number) => void
-  onThumbClick?: (goods: GoodsData, index: number) => void
 }
 
 export default function GoodsList({
@@ -16,8 +15,7 @@ export default function GoodsList({
   id,
   thresholds = [],
   onClick,
-  onAddCart,
-  onThumbClick
+  onAddCart
 }: GoodsListProps) {
   const independentID = id || `goods-list-${Math.floor(Math.random() * 10 ** 8)}`
 
@@ -29,9 +27,6 @@ export default function GoodsList({
     onAddCart?.(goods, index)
   }
 
-  const handleThumbClick = (goods: GoodsData, index: number) => {
-    onThumbClick?.(goods, index)
-  }
 
   return (
     <View
@@ -46,7 +41,6 @@ export default function GoodsList({
           currency={'¥'}
           onClick={() => handleGoodsClick(item, index)}
           onAddCart={() => handleAddCart(item, index)}
-          onThumbClick={() => handleThumbClick(item, index)}
           // className="goods-card-inside"
         />
       ))}