转换实际需水量单位为 m³/h,优化数据展示

This commit is contained in:
JIANG
2026-03-07 17:49:14 +08:00
parent b4ab3e287b
commit 47e47fc605
2 changed files with 27 additions and 25 deletions
+13 -3
View File
@@ -21,7 +21,7 @@ import { useNotification } from "@refinedev/core";
import { config } from "@/config/config"; import { config } from "@/config/config";
import { apiFetch } from "@/lib/apiFetch"; import { apiFetch } from "@/lib/apiFetch";
import { FLOW_DISPLAY_UNIT } from "@utils/units"; import { FLOW_DISPLAY_UNIT, toM3h } from "@utils/units";
// 添加接口定义隐藏按钮的props // 添加接口定义隐藏按钮的props
interface ToolbarProps { interface ToolbarProps {
@@ -467,6 +467,11 @@ const Toolbar: React.FC<ToolbarProps> = ({
if (computedProperties) { if (computedProperties) {
pipeComputedFields.forEach(({ key, label, unit }) => { pipeComputedFields.forEach(({ key, label, unit }) => {
let value = computedProperties[key]; let value = computedProperties[key];
if (key === "flow" && value !== undefined) {
value = toM3h(value, "lps");
}
// 如果是单位水头损失且后端未返回,则通过水头损失/长度计算 (单位 m/km) // 如果是单位水头损失且后端未返回,则通过水头损失/长度计算 (单位 m/km)
if ( if (
key === "unit_headloss" && key === "unit_headloss" &&
@@ -505,10 +510,11 @@ const Toolbar: React.FC<ToolbarProps> = ({
columns: ["demand", "pattern"], columns: ["demand", "pattern"],
rows: Array.from({ length: 5 }, (_, i) => i + 1) rows: Array.from({ length: 5 }, (_, i) => i + 1)
.map((idx) => { .map((idx) => {
const d = properties?.[`demand${idx}`]?.toFixed?.(3); let d = properties?.[`demand${idx}`];
const p = properties?.[`pattern${idx}`]; const p = properties?.[`pattern${idx}`];
// 仅当 demand 有效时展示该行 // 仅当 demand 有效时展示该行
if (d !== undefined && d !== null && d !== "") { if (d !== undefined && d !== null && d !== "") {
d = toM3h(Number(d), "lps");
return [typeof d === "number" ? d.toFixed(3) : d, p ?? "-"]; return [typeof d === "number" ? d.toFixed(3) : d, p ?? "-"];
} }
}) })
@@ -520,10 +526,14 @@ const Toolbar: React.FC<ToolbarProps> = ({
if (computedProperties) { if (computedProperties) {
nodeComputedFields.forEach(({ key, label, unit }) => { nodeComputedFields.forEach(({ key, label, unit }) => {
if (computedProperties[key] !== undefined) { if (computedProperties[key] !== undefined) {
let value = computedProperties[key];
if (key === "actual_demand") {
value = toM3h(value, "lps");
}
result.properties.push({ result.properties.push({
label, label,
value: value:
computedProperties[key].toFixed?.(3) || computedProperties[key], value?.toFixed?.(3) || value,
unit, unit,
}); });
} }
+14 -22
View File
@@ -33,6 +33,7 @@ import { Icon, Style } from "ol/style.js";
import { FeatureLike } from "ol/Feature"; import { FeatureLike } from "ol/Feature";
import { Point } from "ol/geom"; import { Point } from "ol/geom";
import { ContourLayer } from "deck.gl"; import { ContourLayer } from "deck.gl";
import { toM3h } from "@utils/units";
interface MapComponentProps { interface MapComponentProps {
children?: React.ReactNode; children?: React.ReactNode;
@@ -151,7 +152,12 @@ const MapComponent: React.FC<MapComponentProps> = ({ children }) => {
const nodeMap = new Map(currentJunctionCalData.map((r: any) => [r.ID, r])); const nodeMap = new Map(currentJunctionCalData.map((r: any) => [r.ID, r]));
return junctionData.map((j) => { return junctionData.map((j) => {
const record = nodeMap.get(j.id); const record = nodeMap.get(j.id);
return record ? { ...j, [junctionText]: record.value } : j; let val = record ? record.value : undefined;
// 在这合并时将实际需水量从 LPS 转换为大写表示
if (val !== undefined && junctionText === "actualdemand") {
val = toM3h(val, "lps");
}
return record ? { ...j, [junctionText]: val } : j;
}); });
}, [junctionData, currentJunctionCalData, junctionText]); }, [junctionData, currentJunctionCalData, junctionText]);
@@ -161,9 +167,13 @@ const MapComponent: React.FC<MapComponentProps> = ({ children }) => {
const record = linkMap.get(p.id); const record = linkMap.get(p.id);
if (!record) return p; if (!record) return p;
const isFlow = pipeText === "flow"; const isFlow = pipeText === "flow";
let val = record.value;
if (val !== undefined && isFlow) {
val = toM3h(val, "lps");
}
return { return {
...p, ...p,
[pipeText]: isFlow ? Math.abs(record.value) : record.value, [pipeText]: isFlow ? Math.abs(val) : val,
flowFlag: isFlow && record.value < 0 ? -1 : 1, flowFlag: isFlow && record.value < 0 ? -1 : 1,
path: isFlow && record.value < 0 ? [...p.path].reverse() : p.path, path: isFlow && record.value < 0 ? [...p.path].reverse() : p.path,
}; };
@@ -790,15 +800,7 @@ const MapComponent: React.FC<MapComponentProps> = ({ children }) => {
let propPart = ""; let propPart = "";
if (showJunctionTextLayer && d[junctionText] !== undefined) { if (showJunctionTextLayer && d[junctionText] !== undefined) {
const value = (d[junctionText] as number).toFixed(3); const value = (d[junctionText] as number).toFixed(3);
// 根据属性类型添加符号前缀 propPart = `${value}`;
const prefix =
{
pressure: "P:",
head: "H:",
quality: "Q:",
actualdemand: "D:",
}[junctionText] || "";
propPart = `${prefix}${value}`;
} }
if (idPart && propPart) return `${idPart} - ${propPart}`; if (idPart && propPart) return `${idPart} - ${propPart}`;
return idPart || propPart; return idPart || propPart;
@@ -850,17 +852,7 @@ const MapComponent: React.FC<MapComponentProps> = ({ children }) => {
} else { } else {
value = Math.abs(d[pipeText] as number).toFixed(3); value = Math.abs(d[pipeText] as number).toFixed(3);
} }
// 根据属性类型添加符号前缀 propPart = `${value}`;
const prefix =
{
flow: "F:",
velocity: "V:",
headloss: "HL:",
unit_headloss: "UHL:",
diameter: "D:",
friction: "FR:",
}[pipeText] || "";
propPart = `${prefix}${value}`;
} }
if (idPart && propPart) return `${idPart} - ${propPart}`; if (idPart && propPart) return `${idPart} - ${propPart}`;
return idPart || propPart; return idPart || propPart;