From 1fc88995dafa6b79534f9ac08ddc030e0ebad3b9 Mon Sep 17 00:00:00 2001 From: Chiron <598621670@qq.com> Date: Sat, 10 Jan 2026 23:18:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=20API=20=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E9=A1=B5=E9=9D=A2=20URL=20=E9=80=89=E6=8B=A9=E5=92=8C?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 根据监听地址智能选择测试 URL(127.0.0.1/0.0.0.0/局域网IP) - 实时更新测试 URL,切换监听地址时立即反映 - 优化测试状态管理,切换 Tab 时才重置测试结果 - 允许用户对比不同 Provider 的测试结果 --- src/components/api-server/ApiServerPage.tsx | 28 ++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/components/api-server/ApiServerPage.tsx b/src/components/api-server/ApiServerPage.tsx index f43729efd..dadac7102 100644 --- a/src/components/api-server/ApiServerPage.tsx +++ b/src/components/api-server/ApiServerPage.tsx @@ -398,6 +398,14 @@ export function ApiServerPage() { } }, [providerSwitchMsg]); + // 当切换功能 Tab 时,重置所有测试状态 + useEffect(() => { + if (activeTab !== "server") { + setTestResults({}); + setExpandedTest(null); + } + }, [activeTab]); + const handleSetDefaultProvider = async (providerId: string) => { try { await setDefaultProvider(providerId); @@ -432,9 +440,23 @@ export function ApiServerPage() { } }; - const serverUrl = status - ? `http://${status.host}:${status.port}` - : `http://localhost:${config?.server.port ?? 8999}`; + // 根据监听地址智能选择测试 URL + // - 127.0.0.1: 使用 127.0.0.1(仅本机) + // - 0.0.0.0: 使用 127.0.0.1(本机访问所有接口) + // - 局域网 IP: 使用该 IP(允许局域网测试) + const getTestUrl = (host: string, port: number) => { + if (host === "0.0.0.0") { + return `http://127.0.0.1:${port}`; + } + return `http://${host}:${port}`; + }; + + // 使用 editHost 而不是 status.host,这样可以实时反映用户的选择 + const currentHost = status?.running ? status.host : editHost; + const currentPort = status?.running + ? status.port + : parseInt(editPort) || 8999; + const serverUrl = getTestUrl(currentHost, currentPort); const apiKey = config?.server.api_key ?? ""; // 根据 Provider 类型获取测试模型