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

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

@@ -7,7 +7,7 @@ export default function Home() {
return ( return (
<div className="relative w-full h-full overflow-hidden"> <div className="relative w-full h-full overflow-hidden">
<MapComponent> <MapComponent>
<MapToolbar /> <MapToolbar hiddenButtons={["style"]} />
<MonitoringPlaceOptimizationPanel /> <MonitoringPlaceOptimizationPanel />
</MapComponent> </MapComponent>
</div> </div>

View File

@@ -41,7 +41,7 @@ const AnalysisParameters: React.FC = () => {
const [pipePoints, setPipePoints] = useState<PipePoint[]>([]); const [pipePoints, setPipePoints] = useState<PipePoint[]>([]);
const [startTime, setStartTime] = useState<Dayjs | null>(dayjs(new Date())); const [startTime, setStartTime] = useState<Dayjs | null>(dayjs(new Date()));
const [duration, setDuration] = useState<number>(3000); const [duration, setDuration] = useState<number>(3600);
const [schemeName, setSchemeName] = useState<string>( const [schemeName, setSchemeName] = useState<string>(
"FANGAN" + new Date().getTime() "FANGAN" + new Date().getTime()
); );
@@ -52,6 +52,14 @@ const AnalysisParameters: React.FC = () => {
useState<VectorLayer<VectorSource> | null>(null); useState<VectorLayer<VectorSource> | null>(null);
const [highlightFeatures, setHighlightFeatures] = useState<Feature[]>([]); const [highlightFeatures, setHighlightFeatures] = useState<Feature[]>([]);
const [analyzing, setAnalyzing] = useState<boolean>(false); const [analyzing, setAnalyzing] = useState<boolean>(false);
// 检查是否所有必要参数都已填写
const isFormValid =
pipePoints.length > 0 &&
startTime !== null &&
duration > 0 &&
schemeName.trim() !== "";
// 初始化管道图层和高亮图层 // 初始化管道图层和高亮图层
useEffect(() => { useEffect(() => {
if (!map) return; if (!map) return;
@@ -254,11 +262,11 @@ const AnalysisParameters: React.FC = () => {
const burst_size = pipePoints.map((pipe) => const burst_size = pipePoints.map((pipe) =>
parseInt(pipe.area.toString(), 10) parseInt(pipe.area.toString(), 10)
); );
// 格式化开始时间,去除秒部分
const modify_pattern_start_time = startTime const modify_pattern_start_time = startTime
? startTime.format("YYYY-MM-DDTHH:mm:ssZ") ? startTime.format("YYYY-MM-DDTHH:mm:00Z")
: ""; : "";
const modify_total_duration = duration; const modify_total_duration = duration;
const body = { const body = {
name: network, name: network,
modify_pattern_start_time: modify_pattern_start_time, modify_pattern_start_time: modify_pattern_start_time,
@@ -464,7 +472,7 @@ const AnalysisParameters: React.FC = () => {
variant="contained" variant="contained"
size="large" size="large"
onClick={handleAnalyze} onClick={handleAnalyze}
disabled={analyzing} disabled={analyzing || !isFormValid}
className="bg-blue-600 hover:bg-blue-700" className="bg-blue-600 hover:bg-blue-700"
> >
{analyzing ? "方案提交分析中..." : "方案分析"} {analyzing ? "方案提交分析中..." : "方案分析"}

View File

@@ -258,13 +258,12 @@ const SCADADataPanel: React.FC<SCADADataPanelProps> = ({
headerName: deviceLabels?.[id] ?? id, headerName: deviceLabels?.[id] ?? id,
minWidth: 140, minWidth: 140,
flex: 1, flex: 1,
valueFormatter: (params) => { valueFormatter: (value: any) => {
const value = (params as any).value; if (value === null || value === undefined) return "--";
return value === null || value === undefined if (Number.isFinite(Number(value))) {
? "--" return Number(value).toFixed(fractionDigits);
: Number.isFinite(Number(value)) }
? Number(value).toFixed(fractionDigits) return String(value);
: String(value);
}, },
})); }));
@@ -305,52 +304,70 @@ const SCADADataPanel: React.FC<SCADADataPanelProps> = ({
); );
}; };
const chartSection = hasData ? ( const renderChart = () => {
<LineChart if (!hasData) return renderEmpty();
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 tableSection = hasData ? ( return (
<DataGrid <LineChart
rows={rows} dataset={dataset}
columns={columns} height={376}
columnBufferPx={100} margin={{ left: 50, right: 50, top: 20, bottom: 80 }}
sx={{ border: "none", height: "360px" }} xAxis={[
/> {
) : ( dataKey: "time",
renderEmpty() 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 ( return (
<Paper <Paper
@@ -519,7 +536,7 @@ const SCADADataPanel: React.FC<SCADADataPanelProps> = ({
</Box> </Box>
)} )}
{activeTab === "chart" ? chartSection : tableSection} {activeTab === "chart" ? renderChart() : renderTable()}
</Box> </Box>
</Collapse> </Collapse>
</Paper> </Paper>