From 2a48e1f6df9628f699bf8fb8589b4ef947baf846 Mon Sep 17 00:00:00 2001 From: JIANG Date: Thu, 6 Nov 2025 16:52:26 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=9D=A2=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/olmap/SCADADataPanel.tsx | 28 ++++++++++++++++-------- src/components/olmap/SCADADeviceList.tsx | 14 +++++------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/components/olmap/SCADADataPanel.tsx b/src/components/olmap/SCADADataPanel.tsx index 810c6dd..efff612 100644 --- a/src/components/olmap/SCADADataPanel.tsx +++ b/src/components/olmap/SCADADataPanel.tsx @@ -35,6 +35,7 @@ import { GeoJSON } from "ol/format"; import { useGetIdentity } from "@refinedev/core"; import { useNotification } from "@refinedev/core"; import axios from "axios"; +import { set } from "date-fns"; dayjs.extend(utc); dayjs.extend(timezone); @@ -344,9 +345,9 @@ const SCADADataPanel: React.FC = ({ const [isExpanded, setIsExpanded] = useState(true); const [deviceLabels, setDeviceLabels] = useState>({}); const [isCleaning, setIsCleaning] = useState(false); - const [selectedSource, setSelectedSource] = useState<"raw" | "clean" | "sim">( - "raw" - ); + const [selectedSource, setSelectedSource] = useState< + "raw" | "clean" | "sim" | "all" + >("all"); // 获取 SCADA 设备信息,生成 deviceLabels useEffect(() => { @@ -403,7 +404,9 @@ const SCADADataPanel: React.FC = ({ setLoadingState("loading"); setError(null); - + if (deviceIds.length > 1) { + setSelectedSource("clean"); + } try { const { from: rangeFrom, to: rangeTo } = normalizedRange; const result = await customFetcher(deviceIds, { @@ -519,7 +522,8 @@ const SCADADataPanel: React.FC = ({ const dynamic = (() => { if (showCleaning) { - if (deviceIds.length === 1) { + if (selectedSource === "all") { + // 全部模式:显示所有设备的三种数据 return deviceIds.flatMap((id) => [ { field: `${id}_raw`, @@ -562,6 +566,7 @@ const SCADADataPanel: React.FC = ({ }, ]); } else { + // 单一数据源模式:只显示选中的数据源 return deviceIds.map((id) => ({ field: `${id}_${selectedSource}`, headerName: deviceLabels?.[id] ?? id, @@ -688,7 +693,8 @@ const SCADADataPanel: React.FC = ({ ]} series={(() => { if (showCleaning) { - if (deviceIds.length === 1) { + if (selectedSource === "all") { + // 全部模式:显示所有设备的三种数据 return deviceIds.flatMap((id, index) => [ { dataKey: `${id}_raw`, @@ -725,6 +731,7 @@ const SCADADataPanel: React.FC = ({ }, ]); } else { + // 单一数据源模式:只显示选中的数据源 return deviceIds.map((id, index) => ({ dataKey: `${id}_${selectedSource}`, label: deviceLabels?.[id] ?? id, @@ -885,7 +892,7 @@ const SCADADataPanel: React.FC = ({ position: "absolute", top: 80, right: 16, - height: showCleaning && deviceIds.length >= 2 ? "820px" : "760px", + height: "820px", borderRadius: "12px", boxShadow: "0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)", @@ -1049,17 +1056,20 @@ const SCADADataPanel: React.FC = ({ - {showCleaning && deviceIds.length >= 2 && ( + {showCleaning && hasDevices && ( 数据源: + onChange={(_, value: "raw" | "clean" | "sim" | "all") => setSelectedSource(value) } > + {deviceIds.length === 1 && ( + + )} diff --git a/src/components/olmap/SCADADeviceList.tsx b/src/components/olmap/SCADADeviceList.tsx index ddd5d88..f05f9ce 100644 --- a/src/components/olmap/SCADADeviceList.tsx +++ b/src/components/olmap/SCADADeviceList.tsx @@ -135,7 +135,7 @@ const SCADADeviceList: React.FC = ({ const debounceTimerRef = useRef(null); const filterBoxRef = useRef(null); - const [listHeight, setListHeight] = useState(500); + const [listHeight, setListHeight] = useState(560); // 清洗对话框状态 const [cleanDialogOpen, setCleanDialogOpen] = useState(false); @@ -748,13 +748,13 @@ const SCADADeviceList: React.FC = ({ useEffect(() => { const updateListHeight = () => { if (filterBoxRef.current) { - const drawerHeight = 760; // Drawer 总高度 + const drawerHeight = 820; // Drawer 总高度 const headerHeight = 73; // 头部高度(估算) const dividerHeight = 1; // 分隔线高度 const filterBoxHeight = filterBoxRef.current.offsetHeight; const availableHeight = drawerHeight - headerHeight - filterBoxHeight - dividerHeight - 8; // 减去一些边距 - setListHeight(Math.max(availableHeight, 200)); // 最小高度 200 + setListHeight(Math.max(availableHeight, 260)); // 最小高度 260 } }; @@ -777,8 +777,6 @@ const SCADADeviceList: React.FC = ({ showCleaning, ]); - const drawerWidth = 360; - return ( <> {/* 收起时的触发按钮 */} @@ -808,11 +806,11 @@ const SCADADeviceList: React.FC = ({ variant="persistent" hideBackdrop sx={{ - width: isExpanded ? drawerWidth : 0, + width: isExpanded ? 360 : 0, flexShrink: 0, "& .MuiDrawer-paper": { - width: drawerWidth, - height: "760px", + width: 360, + height: "820px", boxSizing: "border-box", position: "absolute", top: 80,