"use client" import { useState } from "react" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Input } from "@/components/ui/input" import { Button } from "@/components/ui/button" import { Loader2 } from "lucide-react" interface Uploader { mid: string name: string fans: number archive_count: number timestamp: number } export default function UploaderSearch() { const [uid, setUid] = useState("") const [uploaders, setUploaders] = useState([]) const [loading, setLoading] = useState(false) const [error, setError] = useState(null) const handleSearch = async () => { if (!uid) { setError("请输入UID") return } setLoading(true) setError(null) try { const response = await fetch(`https://api.ninevocalrank.top/basic/v1/uploader/${uid}`) if (!response.ok) { throw new Error("服务器响应错误") } const data: Uploader = await response.json() setUploaders([data]) // 将单个 UP 主数据包装在数组中 } catch (error) { console.error("搜索UP主时出错:", error) setError("搜索过程中出现错误") } finally { setLoading(false) } } return ( 通过UID搜索UP主
setUid(e.target.value)} />
{error &&

{error}

} {uploaders.length > 0 ? (
    {uploaders.map((uploader) => (
  • {uploader.name}

    UID: {uploader.mid}

    粉丝数: {uploader.fans.toLocaleString()}

    视频数: {uploader.archive_count}

    最后更新: {new Date(uploader.timestamp * 1000).toLocaleString("zh-CN")}

  • ))}
) : ( !loading && !error &&

暂无数据

)}
) }