"use client"; import React, { useEffect, useRef, useState } from "react"; import { Tabs, Swiper, Toast, Image, List, InfiniteScroll } from "antd-mobile"; import PostItem from "@/components/PostItem"; import { sleep } from "antd-mobile/es/utils/sleep"; import "./index.css"; import Link from "next/link"; import BottomNav from "@/components/BottomNav"; import Empty from "@/components/Empty"; import { useRouter } from "next/navigation"; import PostItemSkeleton from "@/components/skeletons/PostItemSkeleton"; const variables = { "@active-line-color": "#f00", // 将主题色改为红色 }; const tabItems = [ { key: "space", title: "空间" }, { key: "post", title: "动态" }, ]; let count = 0; // const scrollHeight = 700; // const scrollHeight = window.innerHeight-126 export default function Space() { 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); // const handleResize = () => { // setScrollHeight(window.innerHeight - 126); // }; // window.addEventListener("resize", handleResize); // return () => { // // window.removeEventListener("resize", handleResize); // }; }, []); 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); }} >
搜索空间 查看推荐
); } const VisitingCard = () => { const router = useRouter(); return (
router.push("/space/person_space")} >
洋洋不是洋妞
); };