"use client"; import React, { useEffect, useRef, useState, Suspense } from "react"; import { Tabs, Swiper, PullToRefresh, Toast, InfiniteScroll, List, Image, } from "antd-mobile"; import PostItem from "../components/PostItem"; import { sleep } from "antd-mobile/es/utils/sleep"; import "./index.css"; import PostItemSkeleton from "@/components/skeletons/PostItemSkeleton"; import Link from "next/link"; const variables = { "@active-line-color": "#f00", // 将主题色改为红色 }; const tabItems = [ { key: "commend", title: "推荐" }, { key: "follow", title: "关注" }, ]; let count = 0; // const scrollHeight = 700; // const scrollHeight = window.innerHeight-126 export default function Home() { const swiperRef = useRef(null); const [activeIndex, setActiveIndex] = useState(0); const [data, setData] = useState([]); const [hasMore, setHasMore] = useState(true); const [scrollHeight, setScrollHeight] = useState(0); // 获取屏幕高度 // const scrollHeight = 600; useEffect(() => { setScrollHeight(window.innerHeight - 126); }, []); async function mockRequest() { if (count >= 5) { return []; } await sleep(2000); count++; return [ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", ]; } async function doRefresh() { await sleep(1000); Toast.show({ icon: "fail", content: "刷新失败", }); throw new Error("刷新失败"); } async function loadMore() { const append = await mockRequest(); setData((val) => [...val, ...append]); setHasMore(append.length > 0); } return (
{ const index = tabItems.findIndex((item) => item.key === key); setActiveIndex(index); swiperRef.current?.swipeTo(index); }} > {tabItems.map((item) => ( ))}
null} ref={swiperRef} defaultIndex={activeIndex} onIndexChange={(index) => { setActiveIndex(index); }} >
); }