Pārlūkot izejas kodu

🔧 chore(env): 更新开发环境API基础URL

- 修改TARO_APP_API_BASE_URL指向新的开发环境地址

💄 style(component): 调整分类侧边栏项样式

- 增加CategorySidebarItem文本区域高度从36rpx到60rpx

💄 style(page): 优化首页商品卡片布局

- 调整商品卡片margin为16rpx 0
- 增加商品卡片最小高度80rpx

🐛 fix(page): 修复首页商品加载和分页问题

- 重构触底加载逻辑,使用ScrollView的onScrollToLower事件替代全局钩子
- 优化getNextPageParam函数,增加完整的分页逻辑调试信息
- 增强API请求和响应的调试日志输出
- 优化无更多数据提示,显示商品总数

📝 docs(page): 更新个人中心版本号

- 将版本信息从v1.0.0更新为v0.0.3
yourname 1 mēnesi atpakaļ
vecāks
revīzija
3727f69352

+ 1 - 1
mini/.env.development

@@ -3,7 +3,7 @@
 
 # API配置
 # 需换成当前项目的
-TARO_APP_API_BASE_URL=https://d8d-ai-vscode-8080-186-175-template-6-group.r.d8d.fun
+TARO_APP_API_BASE_URL=https://d8d-ai-vscode-8080-186-175-template-22-group.r.d8d.fun
 TARO_APP_API_VERSION=v1
 
 # 租户ID

+ 1 - 1
mini/src/components/category/CategorySidebarItem/CategorySidebarItem.css

@@ -28,7 +28,7 @@
 
 .category-sidebar-item__text {
   width: 136rpx;
-  height: 36rpx;
+  height: 60rpx;
   padding: 8rpx 0;
   line-height: 36rpx;
   text-align: center;

+ 2 - 1
mini/src/pages/index/index.css

@@ -70,8 +70,9 @@
   padding: 30rpx 0;
   background: #fff;
   border-radius: 16rpx;
-  margin: 0 0 5rpx 0;
+  margin: 16rpx 0;
   box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
+  min-height: 80rpx;
 }
 
 .loading-text,

+ 54 - 11
mini/src/pages/index/index.tsx

@@ -58,6 +58,7 @@ const HomePage: React.FC = () => {
   } = useInfiniteQuery({
     queryKey: ['home-goods-infinite'],
     queryFn: async ({ pageParam = 1 }) => {
+      console.debug('请求商品数据,页码:', pageParam)
       const response = await goodsClient.$get({
         query: {
           page: pageParam,
@@ -68,11 +69,29 @@ const HomePage: React.FC = () => {
       if (response.status !== 200) {
         throw new Error('获取商品失败')
       }
-      return response.json()
+      const result = await response.json()
+      console.debug('API响应数据:', {
+        page: pageParam,
+        dataCount: result.data?.length || 0,
+        pagination: result.pagination
+      })
+      return result
     },
-    getNextPageParam: (lastPage) => {
+    getNextPageParam: (lastPage, allPages) => {
       const { pagination } = lastPage
       const totalPages = Math.ceil(pagination.total / pagination.pageSize)
+
+      // 调试信息
+      console.debug('分页信息:', {
+        current: pagination.current,
+        pageSize: pagination.pageSize,
+        total: pagination.total,
+        totalPages,
+        hasNext: pagination.current < totalPages,
+        allPagesCount: allPages.length,
+        allGoodsCount: allPages.flatMap(page => page.data).length
+      })
+
       return pagination.current < totalPages ? pagination.current + 1 : undefined
     },
     staleTime: 5 * 60 * 1000,
@@ -105,12 +124,33 @@ const HomePage: React.FC = () => {
     console.error('广告数据获取失败:', adError)
   }
 
-  // 使用Taro全局钩子 - 触底加载更多
-  useReachBottom(() => {
-    if (hasNextPage && !isFetchingNextPage) {
-      fetchNextPage()
-    }
-  })
+  // // 使用Taro全局钩子 - 触底加载更多
+  // useReachBottom(() => {
+  //   if (hasNextPage && !isFetchingNextPage) {
+  //     fetchNextPage()
+  //   }
+  // })
+
+  // 触底加载更多
+  const handleScrollToLower = () => {
+    console.debug('触底加载更多:', {
+      hasNextPage,
+      isFetchingNextPage,
+      allGoodsCount: allGoods.length,
+      pagesCount: data?.pages?.length || 0,
+      currentPage: data?.pages?.[data.pages.length - 1]?.pagination?.current || 0
+    })
+    fetchNextPage();
+    // if (hasNextPage && isFetchingNextPage) {
+    //   console.debug('开始加载下一页...')
+    //   fetchNextPage()
+    // } else {
+    //   console.debug('无法加载下一页,原因:', {
+    //     hasNextPage,
+    //     isFetchingNextPage
+    //   })
+    // }
+  }
 
   // 使用Taro全局钩子 - 下拉刷新
   usePullDownRefresh(() => {
@@ -173,7 +213,8 @@ const HomePage: React.FC = () => {
       />
       <ScrollView
         className="home-scroll-view"
-        scrollY
+        scrollY        
+        onScrollToLower={handleScrollToLower}
       >
         {/* 页面头部 - 搜索栏和轮播图 */}
         <View className="home-page-header">
@@ -250,8 +291,10 @@ const HomePage: React.FC = () => {
               {/* 无更多数据状态 */}
               {!hasNextPage && goodsList.length > 0 && (
                 <View className="no-more-container">
-                  <Text className="no-more-text">已经到底啦</Text>
-                </View>
+                <Text className="no-more-text">
+                  {`已经到底啦 (共${goodsList.length}件商品)`}
+                </Text>
+              </View>
               )}
             </>
           )}

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

@@ -278,7 +278,7 @@ const ProfilePage: React.FC = () => {
         {/* 版本信息 */}
         <View className="pb-8">
           <Text className="text-center text-xs text-gray-400">
-            v1.0.0 - 小程序版
+            v0.0.3 - 小程序版
           </Text>
         </View>
       </ScrollView>