2024-06-24 22:12:13 +08:00
|
|
|
"use client";
|
|
|
|
|
2024-06-25 20:18:37 +08:00
|
|
|
import React, { useEffect, useRef, useState } from "react";
|
|
|
|
import {
|
|
|
|
Tabs,
|
|
|
|
Swiper,
|
|
|
|
PullToRefresh,
|
|
|
|
Toast,
|
|
|
|
InfiniteScroll,
|
|
|
|
List,
|
|
|
|
Image
|
|
|
|
} from "antd-mobile";
|
|
|
|
import { AppstoreOutline } from "antd-mobile-icons";
|
|
|
|
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 searchImg from "@/public/icons/search.png";
|
|
|
|
const variables = {
|
|
|
|
"@active-line-color": "#f00", // 将主题色改为红色
|
|
|
|
};
|
2024-06-24 22:12:13 +08:00
|
|
|
const tabItems = [
|
2024-06-25 20:18:37 +08:00
|
|
|
{ key: "commend", title: "推荐" },
|
|
|
|
{ key: "follow", title: "关注" },
|
|
|
|
];
|
|
|
|
let count = 0;
|
|
|
|
// const scrollHeight = 700;
|
|
|
|
// const scrollHeight = window.innerHeight-126
|
2024-06-24 22:12:13 +08:00
|
|
|
export default function Home() {
|
2024-06-25 20:18:37 +08:00
|
|
|
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);
|
|
|
|
}
|
2024-06-24 22:12:13 +08:00
|
|
|
return (
|
2024-06-25 20:18:37 +08:00
|
|
|
<main className="h-screen">
|
|
|
|
<div className="flex justify-between items-center p-2 custom-tabs text-gray-400">
|
|
|
|
<Tabs
|
2024-06-24 22:12:13 +08:00
|
|
|
activeKey={tabItems[activeIndex].key}
|
2024-06-25 20:18:37 +08:00
|
|
|
onChange={(key) => {
|
|
|
|
const index = tabItems.findIndex((item) => item.key === key);
|
|
|
|
setActiveIndex(index);
|
|
|
|
swiperRef.current?.swipeTo(index);
|
2024-06-24 22:12:13 +08:00
|
|
|
}}
|
|
|
|
>
|
2024-06-25 20:18:37 +08:00
|
|
|
{tabItems.map((item) => (
|
|
|
|
<Tabs.Tab
|
|
|
|
forceRender={false}
|
|
|
|
title={item.title}
|
|
|
|
key={item.key}
|
|
|
|
className="text-left"
|
|
|
|
/>
|
2024-06-24 22:12:13 +08:00
|
|
|
))}
|
|
|
|
</Tabs>
|
2024-06-25 20:18:37 +08:00
|
|
|
<Link href="search" className="w-9 h-9 flex items-center justify-center bg-[#FFFFFF1A] rounded-full"><Image src="/icons/search.png"/></Link>
|
|
|
|
</div>
|
|
|
|
<Swiper
|
|
|
|
className="overflow-visible"
|
|
|
|
direction="horizontal"
|
|
|
|
loop
|
|
|
|
indicator={() => null}
|
|
|
|
ref={swiperRef}
|
|
|
|
defaultIndex={activeIndex}
|
|
|
|
onIndexChange={(index) => {
|
|
|
|
setActiveIndex(index);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Swiper.Item>
|
|
|
|
<PullToRefresh onRefresh={doRefresh}>
|
|
|
|
<List
|
|
|
|
className="p-2 overflow-y-auto scrollbarBox_hidden"
|
|
|
|
style={{ maxHeight: `${scrollHeight}px` }}
|
|
|
|
>
|
|
|
|
<List.Item className="!p-0">
|
|
|
|
<PostItem />
|
|
|
|
</List.Item>
|
|
|
|
<List.Item className="!p-0">
|
|
|
|
<PostItem />
|
|
|
|
</List.Item>
|
|
|
|
<List.Item className="!p-0">
|
|
|
|
<PostItem />
|
|
|
|
</List.Item>
|
|
|
|
<InfiniteScroll loadMore={loadMore} hasMore={hasMore} />
|
|
|
|
</List>
|
|
|
|
</PullToRefresh>
|
|
|
|
</Swiper.Item>
|
|
|
|
<Swiper.Item>
|
|
|
|
<PullToRefresh onRefresh={doRefresh}>
|
|
|
|
<List
|
|
|
|
className="p-2 overflow-y-auto scrollbarBox_hidden"
|
|
|
|
style={{ maxHeight: `${scrollHeight}px` }}
|
|
|
|
>
|
|
|
|
<List.Item className="!p-0">
|
|
|
|
<PostItem follow={true}/>
|
|
|
|
</List.Item>
|
|
|
|
<InfiniteScroll loadMore={loadMore} hasMore={hasMore} />
|
|
|
|
</List>
|
|
|
|
</PullToRefresh>
|
|
|
|
</Swiper.Item>
|
|
|
|
</Swiper>
|
|
|
|
<div className="fixed bottom-0 left-0 w-full">
|
|
|
|
<BottomNav />
|
2024-06-24 22:12:13 +08:00
|
|
|
</div>
|
|
|
|
</main>
|
2024-06-25 20:18:37 +08:00
|
|
|
);
|
2024-06-24 22:12:13 +08:00
|
|
|
}
|