"use client"; import React, { useEffect, useRef, useState } from "react"; import { Input, List, DotLoading, Toast, Image } from "antd-mobile"; import { useRouter } from "next/navigation"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faAngleLeft } from "@fortawesome/free-solid-svg-icons"; import require from "@/utils/require"; import { debounce } from "@/utils/tools"; import Empty from "@/components/Empty"; const newDebounce = debounce(function (fn) { fn && fn(); }, 500); export default function Search() { const router = useRouter(); // 获取屏幕高度 // const scrollHeight = 600; const [searchValue, setSearchValue] = useState(""); const [loading, setLoading] = useState(false); const [streamers, setStreamers] = useState([]); // const [zones, setZones] = useState([]); useEffect(() => {}, []); const isNumeric = (str) => { return /^\d+$/.test(str); }; const getResult = async (value) => { console.log("searchValue", value); const isSearchInt = isNumeric(value); let api = ""; let querryParams = ""; if (isSearchInt) { api = "/api/streamer/list_ext_fuzzily_by_user_id"; querryParams = { user_id: parseInt(value, 10) }; } else { api = "/api/streamer/list_ext_fuzzily_by_name"; querryParams = { name: value }; } try { setLoading(true); const data = await require("POST", api, { body: { ...querryParams, offset: 0, limit: 20, }, }); if (data.ret === -1) { Toast.show({ icon: "fail", content: data.msg, position: "top", }); return; } // if (!ignore) { // const zonesData = data.data.list.filter((item) => item.zones.length > 0); setStreamers(data.data.list); // setZones(zonesData); // } setLoading(false); } catch (error) { console.error(error); } }; return (
{ router.back(); }} />
{ setSearchValue((old) => { let test = (e) => { if (val == "") { setStreamers([]); // setZones([]); return; } getResult(val); }; newDebounce(test); return val; }); }} />
{loading && }
{searchValue && (

{ setSearchValue(""); }} > 清空

)}
{!streamers.length && (
)}
{streamers?.filter((streamer) => streamer.zones.length > 0).length > 0 && (

空间

{(() => { let arr = streamers?.filter( (streamer) => streamer.zones.length > 0 ); return arr?.map((item) => ( )); })()}
)} {streamers.length > 0 && (

个人

{streamers.map((item) => ( ))}
)}
); } const ZoneItem = ({ data, showMore }) => { const router = useRouter(); return ( router.push(`/space/${data.mid}`)} key={data.id} arrow={false} > {
{data?.name} ID {data.user_id}

{data?.bio}

{showMore && (

Ta的动态· {data?.zones[0].zone_moment_count > 99 ? "99+" : data?.zones[0].zone_moment_count} {data?.zones[0].image_count > 0 && ` | 图片·${ data?.zones[0].image_count > 99 ? "99+" : data?.zones[0].image_count }`} {data?.zones[0].video_count > 0 && ` | 视频·${ data?.zones[0].video_count > 99 ? "99+" : data?.zones[0].video_count }`}

{ // if (item.type == "video") { // handleShowVideo(item); // } else { // showPhotos(photos, index); // } // }} >
} width="100%" height="100%" className={`rounded-xl max-w-full`} fit="cover" src={data?.shorts?.videos[0]?.cover_urls[0]} /> {
}
} width={120} height={120} className={`rounded-xl max-w-full`} fit="cover" src={data?.cover?.images[0]?.urls[0]} /> {data.album.images.map((_item, index) => { if (index > 1) return; return (
} width={120} height={120} className={`rounded-xl max-w-full`} fit="cover" src={_item?.urls[0]} /> ); })}
)} }
); };