From b4ab3e287bddbdd1cb226d68af2672b07194aae6 Mon Sep 17 00:00:00 2001 From: JIANG Date: Sat, 7 Mar 2026 17:31:14 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E5=8D=95=E4=BD=8D=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E8=B7=AF=E5=BE=84=EF=BC=8C=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/OlMap/Controls/Toolbar.tsx | 2 +- .../BurstLocation/AnalysisParameters.tsx | 2 +- .../olmap/BurstLocation/LocationResults.tsx | 2 +- .../olmap/BurstLocation/SchemeQuery.tsx | 2 +- .../BurstPipeAnalysis/LocationResults.tsx | 2 +- .../DMALeakDetection/AnalysisParameters.tsx | 2 +- .../DMALeakDetection/RecognitionResults.tsx | 3 +- .../olmap/DMALeakDetection/SchemeQuery.tsx | 2 +- .../olmap/DMALeakDetection/utils.ts | 17 ----------- .../olmap/FlushingAnalysis/SchemeQuery.tsx | 2 +- src/utils/units.ts | 29 +++++++++++++++++++ 11 files changed, 39 insertions(+), 26 deletions(-) create mode 100644 src/utils/units.ts diff --git a/src/app/OlMap/Controls/Toolbar.tsx b/src/app/OlMap/Controls/Toolbar.tsx index 361b137..affaa34 100644 --- a/src/app/OlMap/Controls/Toolbar.tsx +++ b/src/app/OlMap/Controls/Toolbar.tsx @@ -21,7 +21,7 @@ import { useNotification } from "@refinedev/core"; import { config } from "@/config/config"; import { apiFetch } from "@/lib/apiFetch"; -import { FLOW_DISPLAY_UNIT } from "@components/olmap/DMALeakDetection/utils"; +import { FLOW_DISPLAY_UNIT } from "@utils/units"; // 添加接口定义隐藏按钮的props interface ToolbarProps { diff --git a/src/components/olmap/BurstLocation/AnalysisParameters.tsx b/src/components/olmap/BurstLocation/AnalysisParameters.tsx index bf29a84..b082362 100644 --- a/src/components/olmap/BurstLocation/AnalysisParameters.tsx +++ b/src/components/olmap/BurstLocation/AnalysisParameters.tsx @@ -24,7 +24,7 @@ import dayjs, { Dayjs } from "dayjs"; import "dayjs/locale/zh-cn"; import { api } from "@/lib/api"; import { NETWORK_NAME, config } from "@config/config"; -import { FLOW_DISPLAY_UNIT, toM3s } from "../DMALeakDetection/utils"; +import { FLOW_DISPLAY_UNIT, toM3s } from "@utils/units"; import { BurstLocationResult } from "./types"; interface Props { diff --git a/src/components/olmap/BurstLocation/LocationResults.tsx b/src/components/olmap/BurstLocation/LocationResults.tsx index fc3eda1..4c2f747 100644 --- a/src/components/olmap/BurstLocation/LocationResults.tsx +++ b/src/components/olmap/BurstLocation/LocationResults.tsx @@ -29,7 +29,7 @@ import VectorSource from "ol/source/Vector"; import { Stroke, Style, Circle, Fill } from "ol/style"; import { bbox, featureCollection } from "@turf/turf"; import { BurstCandidate, BurstLocationResult } from "./types"; -import { FLOW_DISPLAY_UNIT } from "../DMALeakDetection/utils"; +import { FLOW_DISPLAY_UNIT } from "@utils/units"; interface Props { result: BurstLocationResult | null; diff --git a/src/components/olmap/BurstLocation/SchemeQuery.tsx b/src/components/olmap/BurstLocation/SchemeQuery.tsx index 823d269..141fe44 100644 --- a/src/components/olmap/BurstLocation/SchemeQuery.tsx +++ b/src/components/olmap/BurstLocation/SchemeQuery.tsx @@ -28,7 +28,7 @@ import { BurstLocationSchemeDetail, BurstSchemeRecord, } from "./types"; -import { FLOW_DISPLAY_UNIT } from "../DMALeakDetection/utils"; +import { FLOW_DISPLAY_UNIT } from "@utils/units"; interface Props { onViewResult: (result: BurstLocationResult) => void; diff --git a/src/components/olmap/BurstPipeAnalysis/LocationResults.tsx b/src/components/olmap/BurstPipeAnalysis/LocationResults.tsx index d119b4e..84f05f8 100644 --- a/src/components/olmap/BurstPipeAnalysis/LocationResults.tsx +++ b/src/components/olmap/BurstPipeAnalysis/LocationResults.tsx @@ -32,7 +32,7 @@ import { toLonLat } from "ol/proj"; import moment from "moment"; import "moment-timezone"; import { LocationResult } from "./types"; -import { FLOW_DISPLAY_UNIT } from "../DMALeakDetection/utils"; +import { FLOW_DISPLAY_UNIT } from "@utils/units"; interface LocationResultsProps { results?: LocationResult[]; diff --git a/src/components/olmap/DMALeakDetection/AnalysisParameters.tsx b/src/components/olmap/DMALeakDetection/AnalysisParameters.tsx index 80b2e20..4a796e3 100644 --- a/src/components/olmap/DMALeakDetection/AnalysisParameters.tsx +++ b/src/components/olmap/DMALeakDetection/AnalysisParameters.tsx @@ -20,7 +20,7 @@ import { useNotification } from "@refinedev/core"; import { api } from "@/lib/api"; import { NETWORK_NAME, config } from "@config/config"; import { LeakageResultDetail } from "./types"; -import { FLOW_DISPLAY_UNIT, toM3s } from "./utils"; +import { FLOW_DISPLAY_UNIT, toM3s } from "@utils/units"; interface Props { onResult: (result: LeakageResultDetail) => void; diff --git a/src/components/olmap/DMALeakDetection/RecognitionResults.tsx b/src/components/olmap/DMALeakDetection/RecognitionResults.tsx index 5fa626b..dce5e08 100644 --- a/src/components/olmap/DMALeakDetection/RecognitionResults.tsx +++ b/src/components/olmap/DMALeakDetection/RecognitionResults.tsx @@ -13,7 +13,8 @@ import { } from "@mui/material"; import { FormatListBulleted } from "@mui/icons-material"; import dayjs from "dayjs"; -import { FLOW_DISPLAY_UNIT, getAreaColor, toM3h } from "./utils"; +import { getAreaColor } from "./utils"; +import { FLOW_DISPLAY_UNIT, toM3h } from "@utils/units"; import { LeakageResultDetail } from "./types"; interface Props { diff --git a/src/components/olmap/DMALeakDetection/SchemeQuery.tsx b/src/components/olmap/DMALeakDetection/SchemeQuery.tsx index b3d7eaa..38fb60b 100644 --- a/src/components/olmap/DMALeakDetection/SchemeQuery.tsx +++ b/src/components/olmap/DMALeakDetection/SchemeQuery.tsx @@ -24,7 +24,7 @@ import { useNotification } from "@refinedev/core"; import { api } from "@/lib/api"; import { NETWORK_NAME, config } from "@config/config"; import { LeakageResultDetail, LeakageSchemeRecord } from "./types"; -import { FLOW_DISPLAY_UNIT, toM3h } from "./utils"; +import { FLOW_DISPLAY_UNIT, toM3h } from "@utils/units"; interface Props { onViewResult: (result: LeakageResultDetail) => void; diff --git a/src/components/olmap/DMALeakDetection/utils.ts b/src/components/olmap/DMALeakDetection/utils.ts index e2590e3..bd46411 100644 --- a/src/components/olmap/DMALeakDetection/utils.ts +++ b/src/components/olmap/DMALeakDetection/utils.ts @@ -11,9 +11,6 @@ export const AREA_COLORS = [ "#be123c", ]; -export const FLOW_DISPLAY_UNIT = "m³/h"; -const M3H_FACTOR = 3600; - export const getAreaColor = (areaId: string | number | undefined) => { const text = String(areaId ?? ""); let hash = 0; @@ -22,17 +19,3 @@ export const getAreaColor = (areaId: string | number | undefined) => { } return AREA_COLORS[hash % AREA_COLORS.length]; }; - -export const toM3h = (value: number, sourceUnit: string = "m³/s") => { - if (!Number.isFinite(value)) return Number.NaN; - const normalizedUnit = sourceUnit.trim().toLowerCase(); - if (normalizedUnit === "m³/h") return value; - return value * M3H_FACTOR; -}; - -export const toM3s = (value: number, sourceUnit: string = "m³/h") => { - if (!Number.isFinite(value)) return Number.NaN; - const normalizedUnit = sourceUnit.trim().toLowerCase(); - if (normalizedUnit === "m³/s") return value; - return value / M3H_FACTOR; -}; diff --git a/src/components/olmap/FlushingAnalysis/SchemeQuery.tsx b/src/components/olmap/FlushingAnalysis/SchemeQuery.tsx index 3bd4f0c..2d2d7f2 100644 --- a/src/components/olmap/FlushingAnalysis/SchemeQuery.tsx +++ b/src/components/olmap/FlushingAnalysis/SchemeQuery.tsx @@ -40,7 +40,7 @@ import Feature, { FeatureLike } from "ol/Feature"; import { bbox, featureCollection } from "@turf/turf"; import Timeline from "@app/OlMap/Controls/Timeline"; import { SchemeRecord, SchemaItem } from "./types"; -import { FLOW_DISPLAY_UNIT } from "../DMALeakDetection/utils"; +import { FLOW_DISPLAY_UNIT } from "@utils/units"; interface SchemeQueryProps { schemes?: SchemeRecord[]; diff --git a/src/utils/units.ts b/src/utils/units.ts new file mode 100644 index 0000000..08dcf7e --- /dev/null +++ b/src/utils/units.ts @@ -0,0 +1,29 @@ +export const FLOW_DISPLAY_UNIT = "m³/h"; +const M3H_FACTOR = 3600; + +export const toM3h = (value: number, sourceUnit: string = "m³/s") => { + if (!Number.isFinite(value)) return Number.NaN; + const normalizedUnit = sourceUnit.trim().toLowerCase(); + if (normalizedUnit === "m³/h") return value; + if (normalizedUnit === "lps" || normalizedUnit === "l/s") return value * 3.6; + if (normalizedUnit === "m³/s") return value * M3H_FACTOR; + return value * M3H_FACTOR; +}; + +export const toM3s = (value: number, sourceUnit: string = "m³/h") => { + if (!Number.isFinite(value)) return Number.NaN; + const normalizedUnit = sourceUnit.trim().toLowerCase(); + if (normalizedUnit === "m³/s") return value; + if (normalizedUnit === "lps" || normalizedUnit === "l/s") return value / 1000; + if (normalizedUnit === "m³/h") return value / M3H_FACTOR; + return value / M3H_FACTOR; +}; + +export const toLps = (value: number, sourceUnit: string = "m³/s") => { + if (!Number.isFinite(value)) return Number.NaN; + const normalizedUnit = sourceUnit.trim().toLowerCase(); + if (normalizedUnit === "lps" || normalizedUnit === "l/s") return value; + if (normalizedUnit === "m³/h") return value / 3.6; + if (normalizedUnit === "m³/s") return value * 1000; + return value * 1000; +};