修复爆管分析方案创建时,时间向后偏移一分钟的问题;

This commit is contained in:
JIANG
2025-10-27 10:12:14 +08:00
parent 56d4b5cb46
commit d7e954aa78
3 changed files with 83 additions and 58 deletions

View File

@@ -258,13 +258,12 @@ const SCADADataPanel: React.FC<SCADADataPanelProps> = ({
headerName: deviceLabels?.[id] ?? id,
minWidth: 140,
flex: 1,
valueFormatter: (params) => {
const value = (params as any).value;
return value === null || value === undefined
? "--"
: Number.isFinite(Number(value))
? Number(value).toFixed(fractionDigits)
: String(value);
valueFormatter: (value: any) => {
if (value === null || value === undefined) return "--";
if (Number.isFinite(Number(value))) {
return Number(value).toFixed(fractionDigits);
}
return String(value);
},
}));
@@ -305,52 +304,70 @@ const SCADADataPanel: React.FC<SCADADataPanelProps> = ({
);
};
const chartSection = hasData ? (
<LineChart
dataset={dataset}
height={376}
margin={{ left: 50, right: 50, top: 20, bottom: 80 }}
xAxis={[
{
dataKey: "time",
scaleType: "time",
valueFormatter: (value) =>
value instanceof Date
? dayjs(value).format("MM-DD HH:mm")
: String(value),
},
]}
yAxis={[{ label: "值" }]}
series={deviceIds.map((id) => ({
dataKey: id,
label: deviceLabels?.[id] ?? id,
showMark: false,
curve: "linear",
}))}
slotProps={{
legend: {
direction: "row",
position: { horizontal: "middle", vertical: "bottom" },
},
loadingOverlay: {
style: { backgroundColor: "transparent" },
},
}}
/>
) : (
renderEmpty()
);
const renderChart = () => {
if (!hasData) return renderEmpty();
const tableSection = hasData ? (
<DataGrid
rows={rows}
columns={columns}
columnBufferPx={100}
sx={{ border: "none", height: "360px" }}
/>
) : (
renderEmpty()
);
return (
<LineChart
dataset={dataset}
height={376}
margin={{ left: 50, right: 50, top: 20, bottom: 80 }}
xAxis={[
{
dataKey: "time",
scaleType: "time",
valueFormatter: (value) =>
value instanceof Date
? dayjs(value).format("MM-DD HH:mm")
: String(value),
},
]}
yAxis={[{ label: "值" }]}
series={deviceIds.map((id) => ({
dataKey: id,
label: deviceLabels?.[id] ?? id,
showMark: false,
curve: "linear",
}))}
slotProps={{
legend: {
direction: "row",
position: { horizontal: "middle", vertical: "bottom" },
},
loadingOverlay: {
style: { backgroundColor: "transparent" },
},
}}
/>
);
};
const renderTable = () => {
if (!hasData) return renderEmpty();
console.debug("[SCADADataPanel] 表格数据:", {
rowsCount: rows.length,
columnsCount: columns.length,
sampleRow: rows[0],
columns: columns.map(c => c.field),
});
return (
<DataGrid
rows={rows}
columns={columns}
columnBufferPx={100}
initialState={{
pagination: {
paginationModel: { pageSize: 10, page: 0 },
},
}}
pageSizeOptions={[5, 10, 25, 50]}
sx={{ border: "none", height: "360px" }}
disableRowSelectionOnClick
/>
);
};
return (
<Paper
@@ -519,7 +536,7 @@ const SCADADataPanel: React.FC<SCADADataPanelProps> = ({
</Box>
)}
{activeTab === "chart" ? chartSection : tableSection}
{activeTab === "chart" ? renderChart() : renderTable()}
</Box>
</Collapse>
</Paper>