完善Toolbar和HistoryDataPanel的交互函数

This commit is contained in:
JIANG
2025-12-16 18:30:47 +08:00
parent 05f8e500d6
commit 3a97e01dda
3 changed files with 164 additions and 90 deletions

View File

@@ -648,24 +648,50 @@ const SCADADataPanel: React.FC<SCADADataPanelProps> = ({
}));
}
} else {
return deviceIds.map<GridColDef>((id) => ({
field: id,
headerName: deviceLabels?.[id] ?? id,
minWidth: 140,
flex: 1,
valueFormatter: (value: any) => {
if (value === null || value === undefined) return "--";
if (Number.isFinite(Number(value))) {
return Number(value).toFixed(fractionDigits);
// 非清洗模式:显示所有设备的所有有数据的列
const cols: GridColDef[] = [];
deviceIds.forEach((id) => {
const deviceName = deviceLabels?.[id] ?? id;
// 为每个设备的每种数据类型创建列
const suffixes = [
{ key: 'raw', name: '原始值' },
{ key: 'clean', name: '清洗值' },
{ key: 'sim', name: '模拟值' }
];
suffixes.forEach(({ key, name }) => {
const fieldKey = `${id}_${key}`;
// 检查是否有该字段的数据
const hasData = dataset.some(
(item) => item[fieldKey] !== null && item[fieldKey] !== undefined
);
if (hasData) {
cols.push({
field: fieldKey,
headerName: `${deviceName} (${name})`,
minWidth: 140,
flex: 1,
valueFormatter: (value: any) => {
if (value === null || value === undefined) return "--";
if (Number.isFinite(Number(value))) {
return Number(value).toFixed(fractionDigits);
}
return String(value);
},
});
}
return String(value);
},
}));
});
});
return cols;
}
})();
return [...base, ...dynamic];
}, [deviceIds, deviceLabels, fractionDigits, showCleaning, selectedSource]);
}, [deviceIds, deviceLabels, fractionDigits, showCleaning, selectedSource, dataset]);
const rows = useMemo(
() =>