重构单位导入路径,优化代码结构
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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[];
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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[];
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
Reference in New Issue
Block a user