"use client"; import React, { useState, useEffect, useRef, useCallback } from "react"; import { Image, Toast, Input } from "antd-mobile"; import Empty from "@/components/Empty"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faAngleLeft, faCalendar } from "@fortawesome/free-solid-svg-icons"; import requireAPI from "@/utils/requireAPI"; import { useRouter } from "next/navigation"; import { formatTimestamp } from "@/utils/tools"; export default function SpaceSearch({ navigation }) { const [data, setData] = useState([]); const [search, setSearch] = useState(""); const [isloading, setIsloading] = useState(false); const searchRef = useRef(null); const router = useRouter(); const getData = async (searchValue) => { if (searchValue == "") { return; } if (/[^0-9]/.test(searchValue)) { Toast.show({ icon: "fail", content: "请输入正确的用户ID", position: "top", }); return; } try { setIsloading(true); const body = { member_user_id: Number(searchValue), }; const _data = await requireAPI("POST", "/api/zone/search_zone_member", { body, }); if (_data.ret === -1) { setIsloading(false); Toast.show({ icon: "fail", content: _data.msg, position: "top", }); return; } setData(_data.data.list); } catch (error) { console.error(error); } setIsloading(false); }; //进入页面默认focus useEffect(() => { searchRef.current.focus(); }, []); const updateSearch = (search) => { setSearch(search); if (!search) return; }; //单个成员组件 const renderItem = useCallback((item, index) => { return (
{/* */}
{item?.account?.name}
{item?.is_ironfan == 1 && (
铁粉
)} {item?.is_superfan == 1 && (
超粉
)}
{item?.account?.user_id}
{formatTimestamp(item?.join_ct)}
); }, []); return (
{ router.back(); }} />
getData(search)} > 搜索
{data?.map( (item, index) => renderItem(item, index) // )} {data.length === 0 && (
)}
); }