重构单位导入路径,优化代码结构

This commit is contained in:
JIANG
2026-03-07 17:31:14 +08:00
parent ddb02cc688
commit b4ab3e287b
11 changed files with 39 additions and 26 deletions
@@ -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;
};