import React, { useEffect, useState } from "react"; import { NETWORK_BASE_URL } from "../../constants/system.js"; // 测试链接配置 const TESTING_LINKS = [ { name: "bilibili", url: "https://bilibili.com/", icon: ( ) }, { name: "Github", url: "https://github.com/", icon: ( ) }, { name: "YouTube", url: "https://youtube.com/", icon: ( ) }, { name: "Tiktok", url: "https://tiktok.com/", icon: ( ) }, // ... 其他链接配置类似 ]; export function BotNetwork() { const [linksTime, setLinksTime] = useState(new Array(TESTING_LINKS.length).fill('NaN ms')); const [isLoading, setIsLoading] = useState(false); // 测试单个链接 const testSingleLink = async (url, index) => { try { const response = await fetch(NETWORK_BASE_URL + url); const data = await response.json(); setLinksTime(prev => { const newTimes = [...prev]; newTimes[index] = `${data.time}ms`; return newTimes; }); } catch (error) { console.error(`测试链接失败: ${url}`, error); setLinksTime(prev => { const newTimes = [...prev]; newTimes[index] = '超时'; return newTimes; }); } }; // 一键测速 const handleTestAll = async () => { setIsLoading(true); setLinksTime(new Array(TESTING_LINKS.length).fill('测试中...')); try { await Promise.all( TESTING_LINKS.map((link, index) => testSingleLink(link.url, index) ) ); } finally { setIsLoading(false); } }; return (

🌐网速

{ TESTING_LINKS.map((link, index) => (
{ link.icon } { linksTime[index] }
)) }
); }