"use client"; import React, { useEffect, useRef, useState } from "react"; import { JumboTabs, List, InfiniteScroll, Avatar, Toast, DotLoading, } from "antd-mobile"; // import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation"; import { useSearchParams, usePathname, useParams } from "next/navigation"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faAngleLeft } from "@fortawesome/free-solid-svg-icons"; import Empty from "@/components/Empty"; import styles from "./index.module.scss"; import { handleFollow } from "@/api/public"; import webviewBaseRequest from "@/utils/webviewBaseRequest"; import { generateSignature } from "@/utils/crypto"; import require from "@/utils/require"; import InfiniteScrollContent from "@/components/InfiniteScrollContent"; export default function Relationship() { const [currentKey, setCurrentKey] = useState(""); const [hasMore, setHasMore] = useState(true); // const router = useRouter(); const router = useRouter(); const searchParams = useSearchParams(); const pathname = usePathname(); const params = useParams(); const [scrollHeight, setScrollHeight] = useState(0); const [data, setData] = useState([]); const [offset, setOffset] = useState(0); // 获取屏幕高度 // const scrollHeight = 600; useEffect(() => { if (currentKey) { setOffset(0); setData([]); getData(currentKey, offset).then((res) => { setData(res); }); } }, [currentKey]); useEffect(() => { const key = searchParams.get("key"); // console.log('nnnnn',searchParams.get("key")) key && setCurrentKey(key); }, [searchParams]); async function loadMore(key) { const append = await getData(key, offset); setData((val) => [...val, ...append]); setHasMore(append.length > 0); } const getData = async (key, currentOffset) => { // api/account_relation/list_is_followed const followIds = await require("POST", `/api/account_relation/${ key == "follow" ? "list_follow" : "list_is_followed" }`, { body: { offset: currentOffset, limit: 12 }, }, true); if (followIds.ret === -1) { Toast.show({ icon: "fail", content: data.msg, position: "top", }); return; } if (!followIds.data.list.length) return []; const followsMids = followIds.data.list.map((item) => item.obj_mid); const streamers = await require("POST", `/api/streamer/${ key == "follow" ? "list_ext_by_mids" : "list_others_by_mids" }`, { body: { mids: followsMids, offset: 0, limit: 12 }, }, true); if (streamers.ret === -1) { Toast.show({ icon: "fail", content: data.msg, position: "top", }); return; } const followsDataList = streamers.data.list.map((item) => ({ ...item, isFollowed: true, })); setOffset(streamers.data.offset); return [...followsDataList]; // setMore(temData.data.more); }; const cancleFollow = async (item, index) => { await handleFollow(item.isFollowed, item.mid); const newData = [...data]; newData[index].isFollowed = !item.isFollowed; setData(newData); }; return (
{ router.back(); }} />

关系

{/* 内容 */}
setCurrentKey(key)} activeKey={currentKey} className={`bg-deepBg ${styles.jumboTabs}`} >
) } destroyOnClose={true} > {data.map((item, index) => (

{item.name}

{item.bio}

cancleFollow(item, index)} > {item.isFollowed ? "已关注" : "关注"}
))} loadMore("follow")} hasMore={hasMore} >
) } destroyOnClose={true} > {data.map((item, index) => (

{item.name}

{item.bio}

handleFollow(item.isFollowed, item.mid)} > {item.isFollowed ? "已关注" : "关注"}
))} loadMore("fans")} hasMore={hasMore} >
{/*
*/} ); }