diff --git a/src/app/OlMap/Controls/HistoryDataPanel.tsx b/src/app/OlMap/Controls/HistoryDataPanel.tsx index c8a8232..8d946c7 100644 --- a/src/app/OlMap/Controls/HistoryDataPanel.tsx +++ b/src/app/OlMap/Controls/HistoryDataPanel.tsx @@ -53,14 +53,6 @@ export interface SCADADataPanelProps { scheme_type?: string; /** 策略名称 */ scheme_name?: string; - /** 自定义数据获取器,默认使用后端 API */ - fetchTimeSeriesData?: ( - featureInfos: [string, string][], - range: { from: Date; to: Date }, - type?: "realtime" | "scheme" | "none", - scheme_type?: string, - scheme_name?: string - ) => Promise; /** 默认展示的选项卡 */ defaultTab?: "chart" | "table"; /** Y 轴数值的小数位数 */ @@ -77,7 +69,7 @@ type LoadingState = "idle" | "loading" | "success" | "error"; const fetchFromBackend = async ( featureInfos: [string, string][], range: { from: Date; to: Date }, - type: "realtime" | "scheme" | "none" = "realtime", + type: "realtime" | "scheme" | "none", scheme_type?: string, scheme_name?: string ): Promise => { @@ -332,8 +324,6 @@ const mergeTimeSeriesData = ( return result; }; -const defaultFetcher = fetchFromBackend; - const formatTimestamp = (timestamp: string) => dayjs(timestamp).tz("Asia/Shanghai").format("YYYY-MM-DD HH:mm"); @@ -393,17 +383,12 @@ const emptyStateMessages: Record< const SCADADataPanel: React.FC = ({ featureInfos, - type = "realtime", - scheme_type, + type = "none", + scheme_type = "burst_Analysis", scheme_name, - fetchTimeSeriesData = defaultFetcher, defaultTab = "chart", fractionDigits = 2, }) => { - const customFetcher = useMemo(() => { - return fetchTimeSeriesData; - }, [fetchTimeSeriesData]); - // 从 featureInfos 中提取设备 ID 列表 const deviceIds = useMemo( () => featureInfos.map(([id]) => id), @@ -416,42 +401,11 @@ const SCADADataPanel: React.FC = ({ const [timeSeries, setTimeSeries] = useState([]); const [loadingState, setLoadingState] = useState("idle"); const [error, setError] = useState(null); - const [deviceLabels, setDeviceLabels] = useState>({}); const [selectedSource, setSelectedSource] = useState< "raw" | "clean" | "sim" | "all" >(() => (featureInfos.length === 1 ? "all" : "clean")); const draggableRef = useRef(null); - // 获取 SCADA 设备信息,生成 deviceLabels - useEffect(() => { - const fetchDeviceLabels = async () => { - try { - const url = `${config.MAP_URL}/${config.MAP_WORKSPACE}/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=${config.MAP_WORKSPACE}:geo_scada&outputFormat=application/json`; - const response = await fetch(url); - if (!response.ok) return; - - const json = await response.json(); - const features = new GeoJSON().readFeatures(json); - - const labels = features.reduce>( - (acc, feature) => { - const id = feature.get("id") || feature.getId(); - const name = feature.get("name") || id; - acc[id] = name; - return acc; - }, - {} - ); - - setDeviceLabels(labels); - } catch (error) { - console.error("[SCADADataPanel] 获取设备标签失败:", error); - } - }; - - fetchDeviceLabels(); - }, []); - useEffect(() => { setActiveTab(defaultTab); }, [defaultTab]); @@ -479,7 +433,7 @@ const SCADADataPanel: React.FC = ({ setError(null); try { const { from: rangeFrom, to: rangeTo } = normalizedRange; - const result = await customFetcher( + const result = await fetchFromBackend( featureInfos, { from: rangeFrom.toDate(), @@ -496,15 +450,7 @@ const SCADADataPanel: React.FC = ({ setLoadingState("error"); } }, - [ - featureInfos, - customFetcher, - hasDevices, - normalizedRange, - type, - scheme_type, - scheme_name, - ] + [featureInfos, hasDevices, normalizedRange, type, scheme_type, scheme_name] ); // 设备变化时自动查询 @@ -537,8 +483,6 @@ const SCADADataPanel: React.FC = ({ const cols: GridColDef[] = []; deviceIds.forEach((id) => { - const deviceName = deviceLabels?.[id] ?? id; - // 为每个设备的每种数据类型创建列 const suffixes = [ { key: "clean", name: "清洗值" }, @@ -557,7 +501,7 @@ const SCADADataPanel: React.FC = ({ if (hasData) { cols.push({ field: fieldKey, - headerName: `${deviceName} (${name})`, + headerName: `${id} (${name})`, minWidth: 140, flex: 1, valueFormatter: (value: any) => { @@ -576,7 +520,7 @@ const SCADADataPanel: React.FC = ({ })(); return [...base, ...dynamic]; - }, [deviceIds, deviceLabels, fractionDigits, dataset]); + }, [deviceIds, fractionDigits, dataset]); const rows = useMemo( () => @@ -653,7 +597,7 @@ const SCADADataPanel: React.FC = ({ : "策略模拟"; series.push({ - name: `${deviceLabels?.[id] ?? id} (${displayName})`, + name: `${id} (${displayName})`, type: "line", symbol: "none", sampling: "lttb", @@ -680,7 +624,7 @@ const SCADADataPanel: React.FC = ({ // 如果没有任何数据,则使用fallback if (series.length === 0) { series.push({ - name: deviceLabels?.[id] ?? id, + name: id, type: "line", symbol: "none", sampling: "lttb",