"use client"; import React, { useEffect, useRef, useState } from "react"; import { Input, List, DotLoading, Toast } 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 && (

空间

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

个人

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

{data?.bio}

); };