删除多余的参数,删除多余Label

This commit is contained in:
JIANG
2025-12-17 11:51:24 +08:00
parent 78bdd7ee4b
commit 67c77606a0

View File

@@ -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<TimeSeriesPoint[]>;
/** 默认展示的选项卡 */
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<TimeSeriesPoint[]> => {
@@ -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<SCADADataPanelProps> = ({
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<SCADADataPanelProps> = ({
const [timeSeries, setTimeSeries] = useState<TimeSeriesPoint[]>([]);
const [loadingState, setLoadingState] = useState<LoadingState>("idle");
const [error, setError] = useState<string | null>(null);
const [deviceLabels, setDeviceLabels] = useState<Record<string, string>>({});
const [selectedSource, setSelectedSource] = useState<
"raw" | "clean" | "sim" | "all"
>(() => (featureInfos.length === 1 ? "all" : "clean"));
const draggableRef = useRef<HTMLDivElement>(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<Record<string, string>>(
(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<SCADADataPanelProps> = ({
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<SCADADataPanelProps> = ({
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<SCADADataPanelProps> = ({
const cols: GridColDef[] = [];
deviceIds.forEach((id) => {
const deviceName = deviceLabels?.[id] ?? id;
// 为每个设备的每种数据类型创建列
const suffixes = [
{ key: "clean", name: "清洗值" },
@@ -557,7 +501,7 @@ const SCADADataPanel: React.FC<SCADADataPanelProps> = ({
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<SCADADataPanelProps> = ({
})();
return [...base, ...dynamic];
}, [deviceIds, deviceLabels, fractionDigits, dataset]);
}, [deviceIds, fractionDigits, dataset]);
const rows = useMemo(
() =>
@@ -653,7 +597,7 @@ const SCADADataPanel: React.FC<SCADADataPanelProps> = ({
: "策略模拟";
series.push({
name: `${deviceLabels?.[id] ?? id} (${displayName})`,
name: `${id} (${displayName})`,
type: "line",
symbol: "none",
sampling: "lttb",
@@ -680,7 +624,7 @@ const SCADADataPanel: React.FC<SCADADataPanelProps> = ({
// 如果没有任何数据则使用fallback
if (series.length === 0) {
series.push({
name: deviceLabels?.[id] ?? id,
name: id,
type: "line",
symbol: "none",
sampling: "lttb",