Jelajahi Sumber

🐛 fix(goods-list): 修复分类ID传递和筛选问题

- 修复商品列表页URL参数获取方式,使用Taro.getCurrentInstance().router?.params
- 修复API筛选条件字段名,使用categoryId1替代categoryId
- 确保从分类页跳转时能正确按分类筛选商品

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
yourname 1 bulan lalu
induk
melakukan
2091ea5c72
1 mengubah file dengan 12 tambahan dan 2 penghapusan
  1. 12 2
      mini/src/pages/goods-list/index.tsx

+ 12 - 2
mini/src/pages/goods-list/index.tsx

@@ -17,6 +17,10 @@ export default function GoodsListPage() {
   const [activeCategory, setActiveCategory] = useState('all')
   const { addToCart } = useCart()
 
+  // 获取URL参数中的分类ID
+  const params = Taro.getCurrentInstance().router?.params
+  const categoryId = params?.cateId || ''
+
   const categories = [
     { id: 'all', name: '全部' },
     { id: 'hot', name: '热销' },
@@ -31,14 +35,20 @@ export default function GoodsListPage() {
     hasNextPage,
     refetch
   } = useInfiniteQuery({
-    queryKey: ['goods-infinite', searchKeyword],
+    queryKey: ['goods-infinite', searchKeyword, categoryId],
     queryFn: async ({ pageParam = 1 }) => {
+      // 构建筛选条件
+      const filters: any = { state: 1 } // 只显示可用的商品
+      if (categoryId) {
+        filters.categoryId1 = categoryId
+      }
+
       const response = await goodsClient.$get({
         query: {
           page: pageParam,
           pageSize: 10,
           keyword: searchKeyword,
-          filters: JSON.stringify({ state: 1 }) // 只显示可用的商品
+          filters: JSON.stringify(filters)
         }
       })
       if (response.status !== 200) {