Przeglądaj źródła

✨ feat(mini): 更新生产环境配置并优化商品规格选择流程

- 更新生产环境配置:更换小程序appid和租户ID
- 移除冗余的API注释,保持配置文件整洁
- 更新客服联系电话为新的号码

♻️ refactor(goods-card): 重构商品卡片添加购物车逻辑

- 统一调用父组件的onAddCart方法,由父组件处理规格选择逻辑
- 移除商品卡片内部的规格弹框判断逻辑,简化组件职责

✨ feat(goods-detail): 支持通过URL参数自动打开规格弹框

- 添加useEffect监听URL参数showSpecModal
- 当参数值为'1'且商品有规格选项时,自动设置pendingAction并打开规格弹框

♻️ refactor(goods-list): 重构商品列表页添加购物车逻辑

- 显式定义Goods接口类型,避免类型推断为never
- 为商品列表数据添加明确的类型注解
- 当商品有规格选项时,跳转到详情页并传递showSpecModal=1参数
- 添加详细的调试日志,便于排查问题

♻️ refactor(home): 重构首页添加购物车逻辑

- 添加详细的调试日志,输出hasSpecOptions的计算过程
- 当商品有规格选项时,跳转到详情页并传递showSpecModal=1参数
- 调整轮播图自动播放间隔从4000ms减少到3000ms

♻️ refactor(search-result): 重构搜索结果页添加购物车逻辑

- 移除未使用的导入和状态
- 显式定义Goods接口类型,避免类型推断为never
- 为商品列表数据添加明确的类型注解
- 当商品有规格选项时,跳转到详情页并传递showSpecModal=1参数
- 添加详细的调试日志,便于排查问题
yourname 1 tydzień temu
rodzic
commit
10d219f381

+ 2 - 2
mini/.env.production

@@ -3,9 +3,9 @@
 
 # API配置
 TARO_APP_API_BASE_URL=https://api.yqingkj.com
-# https://d8d-ai-vscode-8080-186-175-template-22-group.r.d8d.fun
+
 
 API_VERSION=v1
 
 # 租户ID
-TARO_APP_TENANT_ID=6
+TARO_APP_TENANT_ID=11

+ 1 - 1
mini/project.config.json

@@ -2,7 +2,7 @@
   "miniprogramRoot": "./dist",
   "projectname": "mini",
   "description": "",
-  "appid": "wx156ad7125e300e81",
+  "appid": "wxee6acd970fefcb75",
   "setting": {
     "urlCheck": false,
     "es6": false,

+ 4 - 9
mini/src/components/goods-card/index.tsx

@@ -110,15 +110,10 @@ export default function GoodsCard({
       return
     }
 
-    // 检查是否有规格选项
-    if (data.hasSpecOptions && data.parentGoodsId && data.parentGoodsId > 0) {
-      // 有多规格选项,弹出规格选择器
-      setPendingAction('add-to-cart')
-      setShowSpecModal(true)
-    } else {
-      // 单规格商品,直接添加到购物车
-      onAddCart?.(data)
-    }
+    // 统一调用 onAddCart,由父组件处理:
+    // - 有规格选项:跳转详情页弹规格框
+    // - 无规格选项:直接加入购物车
+    onAddCart?.(data)
   }
 
   const handleSpecConfirm = (spec: SelectedSpec | null, quantity: number, actionType?: 'add-to-cart' | 'buy-now') => {

+ 9 - 0
mini/src/pages/goods-detail/index.tsx

@@ -90,6 +90,15 @@ export default function GoodsDetailPage() {
 
   const hasSpecOptions = Boolean(childGoodsData && childGoodsData.data && childGoodsData.data.length > 0)
 
+  // 检测URL参数,如果showSpecModal=1则自动弹开规格弹框
+  useEffect(() => {
+    const showSpecModalParam = params?.showSpecModal
+    if (showSpecModalParam === '1' && hasSpecOptions) {
+      setPendingAction('add-to-cart')
+      setShowSpecModal(true)
+    }
+  }, [params?.showSpecModal, hasSpecOptions])
+
   // 格式化价格显示,0显示为"面议"
   const formatPrice = (price: number): string => {
     return price === 0 ? '面议' : `¥${price.toFixed(2)}`

+ 44 - 3
mini/src/pages/goods-list/index.tsx

@@ -11,7 +11,22 @@ import TDesignSearch from '@/components/tdesign/search'
 import type { GoodsData } from '@/components/goods-card'
 
 type GoodsResponse = InferResponseType<typeof goodsClient.$get, 200>
-type Goods = GoodsResponse['data'][0]
+
+// 显式定义 Goods 类型,避免类型推断为 never
+interface Goods {
+  id: number
+  name: string
+  price: number
+  costPrice?: number
+  salesNum: number
+  stock: number
+  spuId: number
+  imageFile?: {
+    fullUrl: string
+  }
+  childGoodsIds?: number[]
+  originPrice?: number
+}
 
 export default function GoodsListPage() {
   const [searchKeyword, setSearchKeyword] = useState('')
@@ -72,7 +87,7 @@ export default function GoodsListPage() {
   })
 
   // 合并所有分页数据
-  const allGoods = data?.pages.flatMap(page => page.data) || []
+  const allGoods: Goods[] = data?.pages.flatMap(page => page.data) || []
 
   // 分享功能 - 分享给好友
   useShareAppMessage(() => {
@@ -137,7 +152,33 @@ export default function GoodsListPage() {
 
   // 添加到购物车
   const handleAddToCart = (goodsData: GoodsData) => {
-    // 直接使用传递的商品数据,不再依赖原始商品查找
+    console.debug('[goods-list] handleAddToCart called', { goodsData, hasSpecOptions: goodsData.hasSpecOptions })
+
+    // 如果有子商品(有规格),跳转到详情页并弹开规格弹框
+    if (goodsData.hasSpecOptions) {
+      let goodsId: number
+      if (typeof goodsData.id === 'number') {
+        goodsId = goodsData.id
+      } else if (typeof goodsData.id === 'string') {
+        goodsId = parseInt(goodsData.id, 10)
+      } else {
+        console.error('商品ID类型无效:', goodsData.id, typeof goodsData.id)
+        Taro.showToast({ title: '商品ID错误', icon: 'none' })
+        return
+      }
+      if (isNaN(goodsId)) {
+        console.error('商品ID解析失败:', goodsData.id)
+        Taro.showToast({ title: '商品ID错误', icon: 'none' })
+        return
+      }
+      // 跳转到详情页,并传递 showSpecModal=1 参数,让详情页自动弹开规格弹框
+      Taro.navigateTo({
+        url: `/pages/goods-detail/index?id=${goodsId}&showSpecModal=1`
+      })
+      return
+    }
+
+    // 没有子商品,直接加入购物车
     const id = parseInt(goodsData.id)
     if (isNaN(id)) {
       console.error('商品ID解析失败:', goodsData.id)

+ 48 - 3
mini/src/pages/index/index.tsx

@@ -150,6 +150,23 @@ const HomePage: React.FC = () => {
     // 根据GoodsServiceMt实现,父商品返回childGoodsIds字段
     const childGoodsIds = (goods as any).childGoodsIds
     const hasSpecOptions = goods.spuId === 0 && childGoodsIds && childGoodsIds.length > 0
+
+    // 调试日志:输出 hasSpecOptions 的计算过程
+    console.log('[convertToGoodsData]', {
+      goodsId: goods.id,
+      goodsName: goods.name,
+      spuId: goods.spuId,
+      childGoodsIds: childGoodsIds,
+      childGoodsIdsLength: childGoodsIds?.length || 0,
+      hasSpecOptions,
+      reason: hasSpecOptions
+        ? '父商品且有子商品'
+        : goods.spuId !== 0
+          ? '不是父商品(spuId !== 0)'
+          : !childGoodsIds || childGoodsIds.length === 0
+            ? '没有子商品列表'
+            : '未知原因'
+    })
     // parentGoodsId: 如果是父商品,parentGoodsId = goods.id;如果是子商品,parentGoodsId = goods.spuId
     const parentGoodsId = goods.spuId === 0 ? goods.id : goods.spuId
     const imageUrl = goods?.imageFile?.fullUrl || ''
@@ -398,8 +415,36 @@ const HomePage: React.FC = () => {
 
   // 添加购物车
   const handleAddCart = (goods: GoodsData, index: number) => {
-    console.debug('[home] handleAddCart called', { goods, index, goodsId: goods.id, goodsIdType: typeof goods.id })
-    // 直接使用传递的商品数据,不再依赖原始商品查找
+    console.debug("dddddd");
+    console.log("dddddd");
+    console.debug('[home] handleAddCart called', { goods, index, goodsId: goods.id, goodsIdType: typeof goods.id, hasSpecOptions: goods.hasSpecOptions })
+    console.log('[home] handleAddCart called', { goods, index, goodsId: goods.id, goodsIdType: typeof goods.id, hasSpecOptions: goods.hasSpecOptions })
+
+    // 如果有子商品(有规格),跳转到详情页并弹开规格弹框
+    if (goods.hasSpecOptions) {
+      let goodsId: number
+      if (typeof goods.id === 'number') {
+        goodsId = goods.id
+      } else if (typeof goods.id === 'string') {
+        goodsId = parseInt(goods.id, 10)
+      } else {
+        console.error('商品ID类型无效:', goods.id, typeof goods.id)
+        Taro.showToast({ title: '商品ID错误', icon: 'none' })
+        return
+      }
+      if (isNaN(goodsId)) {
+        console.error('商品ID解析失败:', goods.id)
+        Taro.showToast({ title: '商品ID错误', icon: 'none' })
+        return
+      }
+      // 跳转到详情页,并传递 showSpecModal=1 参数,让详情页自动弹开规格弹框
+      Taro.navigateTo({
+        url: `/pages/goods-detail/index?id=${goodsId}&showSpecModal=1`
+      })
+      return
+    }
+
+    // 没有子商品,直接加入购物车
     // 安全解析商品ID:支持数字和字符串类型
     let id: number
     if (typeof goods.id === 'number') {
@@ -499,7 +544,7 @@ const HomePage: React.FC = () => {
                 }))}
                 height={800}
                 autoplay={true}
-                interval={4000}
+                interval={3000}
                 circular={true}
                 imageMode="aspectFit"
               />

+ 1 - 1
mini/src/pages/profile/index.tsx

@@ -224,7 +224,7 @@ const ProfilePage: React.FC = () => {
 
   const handleCallCustomerService = () => {
     Taro.makePhoneCall({
-      phoneNumber: '13858628819'
+      phoneNumber: '18756031303'
     })
   }
 

+ 45 - 5
mini/src/pages/search-result/index.tsx

@@ -1,9 +1,8 @@
-import React, { useState, useEffect } from 'react'
+import React, { useState } from 'react'
 import { View, Text, ScrollView, Input } from '@tarojs/components'
 import { useInfiniteQuery } from '@tanstack/react-query'
 import Taro, { useRouter } from '@tarojs/taro'
 import { Navbar } from '@/components/ui/navbar'
-import TDesignSearch from '@/components/tdesign/search'
 import GoodsList from '@/components/goods-list'
 import { goodsClient } from '@/api'
 import { InferResponseType } from 'hono'
@@ -12,7 +11,22 @@ import type { GoodsData } from '@/components/goods-card'
 import './index.css'
 
 type GoodsResponse = InferResponseType<typeof goodsClient.$get, 200>
-type Goods = GoodsResponse['data'][0]
+
+// 显式定义 Goods 类型,避免类型推断为 never
+interface Goods {
+  id: number
+  name: string
+  price: number
+  costPrice?: number
+  salesNum: number
+  stock: number
+  spuId: number
+  imageFile?: {
+    fullUrl: string
+  }
+  childGoodsIds?: number[]
+  originPrice?: number
+}
 
 const SearchResultPage: React.FC = () => {
   const { addToCart } = useCart()
@@ -60,7 +74,7 @@ const SearchResultPage: React.FC = () => {
   })
 
   // 合并所有分页数据
-  const allGoods = data?.pages.flatMap(page => page.data) || []
+  const allGoods: Goods[] = data?.pages.flatMap(page => page.data) || []
 
   // 触底加载更多
   const handleScrollToLower = () => {
@@ -112,7 +126,33 @@ const SearchResultPage: React.FC = () => {
 
   // 添加到购物车
   const handleAddToCart = (goodsData: GoodsData) => {
-    // 直接使用传递的商品数据,不再依赖原始商品查找
+    console.debug('[search-result] handleAddToCart called', { goodsData, hasSpecOptions: goodsData.hasSpecOptions })
+
+    // 如果有子商品(有规格),跳转到详情页并弹开规格弹框
+    if (goodsData.hasSpecOptions) {
+      let goodsId: number
+      if (typeof goodsData.id === 'number') {
+        goodsId = goodsData.id
+      } else if (typeof goodsData.id === 'string') {
+        goodsId = parseInt(goodsData.id, 10)
+      } else {
+        console.error('商品ID类型无效:', goodsData.id, typeof goodsData.id)
+        Taro.showToast({ title: '商品ID错误', icon: 'none' })
+        return
+      }
+      if (isNaN(goodsId)) {
+        console.error('商品ID解析失败:', goodsData.id)
+        Taro.showToast({ title: '商品ID错误', icon: 'none' })
+        return
+      }
+      // 跳转到详情页,并传递 showSpecModal=1 参数,让详情页自动弹开规格弹框
+      Taro.navigateTo({
+        url: `/pages/goods-detail/index?id=${goodsId}&showSpecModal=1`
+      })
+      return
+    }
+
+    // 没有子商品,直接加入购物车
     const id = parseInt(goodsData.id)
     if (isNaN(id)) {
       console.error('商品ID解析失败:', goodsData.id)