"use client"; import React, { useEffect, useRef, useState } from "react"; import { Box, Drawer, Tabs, Tab, Typography, IconButton, Tooltip, } from "@mui/material"; import { ChevronRight, ChevronLeft, Analytics as AnalyticsIcon, Search as SearchIcon, MyLocation as MyLocationIcon, Handyman as HandymanIcon, } from "@mui/icons-material"; import AnalysisParameters from "./AnalysisParameters"; import SchemeQuery from "./SchemeQuery"; import LocationResults from "./LocationResults"; import ValveIsolation from "./ValveIsolation"; import ContaminantAnalysisParameters from "../ContaminantSimulation/AnalysisParameters"; import ContaminantSchemeQuery from "../ContaminantSimulation/SchemeQuery"; import ContaminantResultsPanel from "../ContaminantSimulation/ResultsPanel"; import axios from "axios"; import { config } from "@config/config"; import { useNotification } from "@refinedev/core"; import { useData } from "@app/OlMap/MapComponent"; import { LocationResult, SchemeRecord } from "./types"; interface TabPanelProps { children?: React.ReactNode; index: number; value: number; } const TabPanel: React.FC = ({ children, value, index }) => { return ( ); }; interface BurstPipeAnalysisPanelProps { open?: boolean; onToggle?: () => void; } type PanelMode = "burst" | "contaminant"; const BurstPipeAnalysisPanel: React.FC = ({ open: controlledOpen, onToggle, }) => { const [internalOpen, setInternalOpen] = useState(true); const [currentTab, setCurrentTab] = useState(0); const [panelMode, setPanelMode] = useState("burst"); const previousMapText = useRef<{ junction?: string; pipe?: string } | null>( null, ); const data = useData(); // 持久化方案查询结果 const [schemes, setSchemes] = useState([]); // 定位结果数据 const [locationResults, setLocationResults] = useState([]); const { open } = useNotification(); // 使用受控或非受控状态 const isOpen = controlledOpen !== undefined ? controlledOpen : internalOpen; const handleToggle = () => { if (onToggle) { onToggle(); } else { setInternalOpen(!internalOpen); } }; const handleTabChange = (_event: React.SyntheticEvent, newValue: number) => { setCurrentTab(newValue); }; const handleLocateScheme = async (scheme: SchemeRecord) => { try { const response = await axios.get( `${config.BACKEND_URL}/api/v1/burst-locate-result/${scheme.schemeName}`, ); setLocationResults(response.data); setCurrentTab(2); // 切换到定位结果标签页 } catch (error) { console.error("获取定位结果失败:", error); open?.({ type: "error", message: "获取定位结果失败", description: "无法从服务器获取该方案的定位结果", }); } }; const drawerWidth = 520; const isBurstMode = panelMode === "burst"; const panelTitle = isBurstMode ? "爆管分析" : "水质模拟"; return ( <> {/* 收起时的触发按钮 */} {!isOpen && ( {panelTitle} )} {/* 主面板 */} {/* 头部 */} {panelTitle} {/* Tabs 导航 */} setPanelMode(value)} variant="fullWidth" sx={{ minHeight: 46, "& .MuiTab-root": { minHeight: 46, textTransform: "none", fontSize: "0.8rem", fontWeight: 600, }, "& .Mui-selected": { color: "#257DD4", }, "& .MuiTabs-indicator": { backgroundColor: "#257DD4", }, }} > } iconPosition="start" label="分析要件" /> } iconPosition="start" label="方案查询" /> } iconPosition="start" label={isBurstMode ? "定位结果" : "模拟结果"} /> {isBurstMode && ( } iconPosition="start" label="关阀分析" /> )} {/* Tab 内容 */} {isBurstMode ? ( ) : ( )} {isBurstMode ? ( ) : ( setCurrentTab(2)} /> )} {isBurstMode ? ( ) : ( )} {isBurstMode && ( )} ); }; export default BurstPipeAnalysisPanel;