From ba6caabbc66da420d71efa4842eb7e246069d60c Mon Sep 17 00:00:00 2001 From: hhhhsc701 <56435672+hhhhsc701@users.noreply.github.com> Date: Thu, 30 Oct 2025 20:21:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=89=8D=E7=AB=AF=E5=A2=9E=E5=8A=A0=E5=AF=B9de?= =?UTF-8?q?er-flow=E6=9C=8D=E5=8A=A1=E7=9A=84=E6=A3=80=E6=B5=8B=20(#42)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 前端增加对deer-flow服务的检测 (#42) --- frontend/src/pages/Home/Home.tsx | 55 ++++++++++++++++++++++++++++++-- frontend/src/routes/routes.ts | 2 +- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/frontend/src/pages/Home/Home.tsx b/frontend/src/pages/Home/Home.tsx index 19479b9..b9133f6 100644 --- a/frontend/src/pages/Home/Home.tsx +++ b/frontend/src/pages/Home/Home.tsx @@ -10,11 +10,60 @@ import { GitBranch, } from "lucide-react"; import { features, menuItems } from "../Layout/menu"; +import { useState } from 'react'; import { useNavigate } from "react-router"; import { Card } from "antd"; export default function WelcomePage() { const navigate = useNavigate(); + const [isChecking, setIsChecking] = useState(false); + + // 检查接口连通性的函数 + const checkDeerFlowDeploy = async (): Promise => { + try { + const response = await fetch('/deer-flow-backend/config', { // 替换为你的实际接口地址 + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + timeout: 5000, // 5秒超时 + }); + + // 检查 HTTP 状态码在 200-299 范围内 + const contentType = response.headers.get("content-type"); + if (contentType && contentType.includes('application/json')) { + return true; + } + } catch (error) { + console.error('接口检查失败:', error); + } + return false; + }; + + const handleChatClick = async () => { + if (isChecking) return; // 防止重复点击 + + setIsChecking(true); + + try { + const isDeerFlowDeploy = await checkDeerFlowDeploy(); + + if (isDeerFlowDeploy) { + // 接口正常,执行原有逻辑 + window.location.href = "/chat"; + } else { + // 接口异常,使用 navigate 跳转 + navigate("/chat"); + } + } catch (error) { + // 发生错误时也使用 navigate 跳转 + console.error('检查过程中发生错误:', error); + navigate("/chat"); + } finally { + setIsChecking(false); + } + }; + return (
@@ -40,11 +89,11 @@ export default function WelcomePage() { 开始使用 navigate("/chat")} - className="cursor-pointer rounded px-4 py-2 inline-flex items-center bg-gradient-to-r from-purple-600 to-pink-600 hover:from-purple-700 hover:to-pink-700 text-white shadow-lg" + onClick={handleChatClick} + className="cursor-pointer rounded px-4 py-2 inline-flex items-center bg-gradient-to-r from-purple-600 to-pink-600 hover:from-purple-700 hover:to-pink-700 text-white shadow-lg disabled:opacity-50 disabled:cursor-not-allowed" > - 对话助手 + {isChecking ? '检查中...' : '对话助手'} navigate("/orchestration")} diff --git a/frontend/src/routes/routes.ts b/frontend/src/routes/routes.ts index 9d914bc..7feb4d6 100644 --- a/frontend/src/routes/routes.ts +++ b/frontend/src/routes/routes.ts @@ -43,9 +43,9 @@ import RatioTasksPage from "@/pages/RatioTask/RatioTask"; import CreateRatioTask from "@/pages/RatioTask/CreateRatioTask"; import OrchestrationPage from "@/pages/Orchestration/Orchestration"; import WorkflowEditor from "@/pages/Orchestration/WorkflowEditor"; -import AgentPage from "@/pages/Agent/Agent"; import SettingsPage from "@/pages/SettingsPage/SettingsPage"; import { withErrorBoundary } from "@/components/ErrorBoundary"; +import AgentPage from "@/pages/Agent/Agent.tsx"; const router = createBrowserRouter([ {