"use client"; import { useState } from "react"; import { Link2, LoaderCircle, PlugZap, Save } from "lucide-react"; import { toast } from "sonner"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Card, CardContent } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { testProxy, type ProxyTestResult } from "@/lib/api"; import { useSettingsStore } from "../store"; export function ProxySettingsCard() { const [isTesting, setIsTesting] = useState(false); const [testResult, setTestResult] = useState(null); const config = useSettingsStore((state) => state.config); const isLoadingConfig = useSettingsStore((state) => state.isLoadingConfig); const isSavingConfig = useSettingsStore((state) => state.isSavingConfig); const setProxy = useSettingsStore((state) => state.setProxy); const saveConfig = useSettingsStore((state) => state.saveConfig); const proxy = config?.proxy ?? ""; const handleTest = async () => { const candidate = proxy.trim(); if (!candidate) { toast.error("请先填写代理地址"); return; } setIsTesting(true); setTestResult(null); try { const data = await testProxy(candidate); setTestResult(data.result); if (data.result.ok) { toast.success(`代理可用(${data.result.latency_ms} ms,HTTP ${data.result.status})`); } else { toast.error(`代理不可用:${data.result.error ?? "未知错误"}`); } } catch (error) { toast.error(error instanceof Error ? error.message : "测试代理失败"); } finally { setIsTesting(false); } }; return (

全局代理

为系统中的出站请求配置统一代理,保存后会立即生效。

{proxy.trim() ? "已配置" : "未配置"}
{isLoadingConfig ? (
) : ( <>
{ setProxy(event.target.value); setTestResult(null); }} placeholder="http://user:pass@127.0.0.1:7890" className="h-11 rounded-xl border-stone-200 bg-white" />

留空表示不使用代理。请按完整地址填写,例如 `http://127.0.0.1:7890`、`http://用户名:密码@127.0.0.1:7890` 或 `socks5://127.0.0.1:7890`。

{testResult ? (
{testResult.ok ? `代理可用:HTTP ${testResult.status},用时 ${testResult.latency_ms} ms` : `代理不可用:${testResult.error ?? "未知错误"}(用时 ${testResult.latency_ms} ms)`}
) : null}
)}
); }