"use client"; import React, { useState } from 'react'; import { Box, TextField, Button, Typography, Card, CardContent, Chip } from '@mui/material'; import axios from 'axios'; import { config, NETWORK_NAME } from '@config/config'; import { ValveIsolationResult } from './types'; import { useNotification } from "@refinedev/core"; const ValveIsolation: React.FC = () => { const [pipeId, setPipeId] = useState(''); const [loading, setLoading] = useState(false); const [result, setResult] = useState(null); const { open } = useNotification(); const handleAnalyze = async () => { if (!pipeId.trim()) { open?.({ type: 'error', message: '请输入管段ID' }); return; } setLoading(true); setResult(null); try { const response = await axios.get(`${config.BACKEND_URL}/api/v1/valve_isolation_analysis`, { params: { network: NETWORK_NAME, accident_element: pipeId } }); setResult(response.data); open?.({ type: 'success', message: '分析成功' }); } catch (error) { console.error(error); open?.({ type: 'error', message: '分析失败', description: '无法获取关阀分析结果' }); } finally { setLoading(false); } }; return ( {/* Input Section */} setPipeId(e.target.value)} placeholder="请输入管段ID" /> {/* Results Section */} {result && ( 分析结果 事故类型: {result.accident_type} 受影响节点数: {result.affected_nodes?.length || 0} 必须关闭阀门 ({result.must_close_valves?.length || 0}) {result.must_close_valves?.length > 0 ? ( {result.must_close_valves.map(v => ( ))} ) : } 可选关闭阀门 ({result.optional_valves?.length || 0}) {result.optional_valves?.length > 0 ? ( {result.optional_valves.map(v => ( ))} ) : } 受影响节点 ({result.affected_nodes?.length || 0}) {result.affected_nodes?.length > 0 ? ( {result.affected_nodes.join(', ')} ) : } )} ); }; export default ValveIsolation;