|
|
@@ -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>
|
|
|
)}
|
|
|
</>
|
|
|
)}
|