|
@@ -12,7 +12,7 @@ import { useAuth } from '@/utils/auth'
|
|
|
import { useCart } from '@/contexts/CartContext'
|
|
import { useCart } from '@/contexts/CartContext'
|
|
|
import { Navbar } from '@/components/ui/navbar'
|
|
import { Navbar } from '@/components/ui/navbar'
|
|
|
import { Carousel } from '@/components/ui/carousel'
|
|
import { Carousel } from '@/components/ui/carousel'
|
|
|
-import Taro from '@tarojs/taro'
|
|
|
|
|
|
|
+import Taro, { usePullDownRefresh, useReachBottom } from '@tarojs/taro'
|
|
|
|
|
|
|
|
type GoodsResponse = InferResponseType<typeof goodsClient.$get, 200>
|
|
type GoodsResponse = InferResponseType<typeof goodsClient.$get, 200>
|
|
|
type Goods = GoodsResponse['data'][0]
|
|
type Goods = GoodsResponse['data'][0]
|
|
@@ -53,7 +53,8 @@ const HomePage: React.FC = () => {
|
|
|
isFetchingNextPage,
|
|
isFetchingNextPage,
|
|
|
fetchNextPage,
|
|
fetchNextPage,
|
|
|
hasNextPage,
|
|
hasNextPage,
|
|
|
- error
|
|
|
|
|
|
|
+ error,
|
|
|
|
|
+ refetch
|
|
|
} = useInfiniteQuery({
|
|
} = useInfiniteQuery({
|
|
|
queryKey: ['home-goods-infinite'],
|
|
queryKey: ['home-goods-infinite'],
|
|
|
queryFn: async ({ pageParam = 1 }) => {
|
|
queryFn: async ({ pageParam = 1 }) => {
|
|
@@ -104,12 +105,19 @@ const HomePage: React.FC = () => {
|
|
|
console.error('广告数据获取失败:', adError)
|
|
console.error('广告数据获取失败:', adError)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 触底加载更多
|
|
|
|
|
- const handleScrollToLower = () => {
|
|
|
|
|
|
|
+ // 使用Taro全局钩子 - 触底加载更多
|
|
|
|
|
+ useReachBottom(() => {
|
|
|
if (hasNextPage && !isFetchingNextPage) {
|
|
if (hasNextPage && !isFetchingNextPage) {
|
|
|
fetchNextPage()
|
|
fetchNextPage()
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ // 使用Taro全局钩子 - 下拉刷新
|
|
|
|
|
+ usePullDownRefresh(() => {
|
|
|
|
|
+ refetch().finally(() => {
|
|
|
|
|
+ Taro.stopPullDownRefresh()
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
// // 商品点击
|
|
// // 商品点击
|
|
|
// const handleGoodsClick = (goods: GoodsData, index: number) => {
|
|
// const handleGoodsClick = (goods: GoodsData, index: number) => {
|
|
@@ -166,7 +174,6 @@ const HomePage: React.FC = () => {
|
|
|
<ScrollView
|
|
<ScrollView
|
|
|
className="home-scroll-view"
|
|
className="home-scroll-view"
|
|
|
scrollY
|
|
scrollY
|
|
|
- onScrollToLower={handleScrollToLower}
|
|
|
|
|
>
|
|
>
|
|
|
{/* 页面头部 - 搜索栏和轮播图 */}
|
|
{/* 页面头部 - 搜索栏和轮播图 */}
|
|
|
<View className="home-page-header">
|
|
<View className="home-page-header">
|