Sfoglia il codice sorgente

🐛 fix(category): 修复分类页面子分类显示问题

- 修改子分类获取逻辑,临时使用当前选中分类自身代替子分类
- 修复分类ID类型不匹配问题,将number类型ID转为string
- 为Tabbar组件添加类型断言,确保类型匹配
yourname 1 mese fa
parent
commit
e49426be7a
1 ha cambiato i file con 7 aggiunte e 4 eliminazioni
  1. 7 4
      mini/src/pages/category/index.tsx

+ 7 - 4
mini/src/pages/category/index.tsx

@@ -4,7 +4,7 @@ import { useQuery } from '@tanstack/react-query';
 import { goodsCategoryClient, advertisementClient } from '@/api';
 import CategorySidebar from '@/components/category/CategorySidebar';
 import CategorySidebarItem from '@/components/category/CategorySidebarItem';
-import CategoryTabbar from '@/components/category/CategoryTabbar';
+import CategoryTabbar, { TabItem } from '@/components/category/CategoryTabbar';
 import { Image } from '@/components/ui/image';
 import TDesignToast from '@/components/tdesign/toast';
 import { navigateTo } from '@tarojs/taro';
@@ -78,8 +78,11 @@ const CategoryPage: React.FC = () => {
   // 当前选中的一级分类
   const currentCategory = categories[activeCategoryIndex];
 
+  // 当前一级分类的子分类, 当前先用当前选中的分类自身代替
+  const subCategories = categories.filter(item => item.id === currentCategory.id);
+
   // 当前一级分类的子分类
-  const subCategories = currentCategory?.child_cate || [];
+  // const subCategories = currentCategory?.child_cate || [];
 
   // 广告图片
   const advertisementImage = advertisements[0]?.imageFile?.fullUrl || '';
@@ -163,9 +166,9 @@ const CategoryPage: React.FC = () => {
               <View className="sub-category-tabbar">
                 <CategoryTabbar
                   tabList={subCategories.map((cat: Category) => ({
-                    id: cat.id,
+                    id: cat.id.toString(),
                     name: cat.name,
-                  }))}
+                  } as TabItem))}
                   currentActive={activeSubCategoryId}
                   onChange={handleSubCategoryChange}
                   showMore={true}