zhangwencui
2026-11-02 dab35bff798cfce2ddf7e8a67e4e1cdb144f5b4c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import type { EnergyAlertMetric, EnergyType } from "../../api/energy";
 
export const energyOptions: Array<{ label: string; value: EnergyType }> = [
  { label: "水", value: "WATER" },
  { label: "电", value: "ELECTRICITY" },
  { label: "蒸汽", value: "STEAM" },
];
export const energyInfo: Record<EnergyType, { name: string; unit: string; color: string; tone: string }> = {
  WATER: { name: "水", unit: "m³", color: "#1677ff", tone: "tag-blue" },
  ELECTRICITY: { name: "电", unit: "kWh", color: "#d48806", tone: "tag-orange" },
  STEAM: { name: "蒸汽", unit: "t", color: "#389e0d", tone: "tag-green" },
};
export const productOptions = ["燕窝", "滋补品原浆", "公用能耗", "其他"];
export const areaOptions = ["燕窝生产区", "原浆生产区", "清洗区", "灭菌区", "灌装包装区", "动力站", "仓储区", "办公生活区"];
export const purposeOptions = ["原料清洗", "设备清洗 / CIP", "蒸煮提取", "灭菌", "灌装包装", "制冷", "采暖", "日常用能"];
export const metricOptions: Array<{ label: string; value: EnergyAlertMetric }> = [
  { label: "每日用量", value: "QUANTITY" },
  { label: "每日费用", value: "AMOUNT" },
  { label: "每月用量", value: "MONTH_QUANTITY" },
  { label: "每月费用", value: "MONTH_AMOUNT" },
];
 
export function numberText(value: number | undefined, digits = 3) {
  return Number(value ?? 0).toLocaleString("zh-CN", { maximumFractionDigits: digits, minimumFractionDigits: digits === 2 ? 2 : 0 });
}
export function today() {
  const date = new Date();
  const y = date.getFullYear();
  const m = String(date.getMonth() + 1).padStart(2, "0");
  const d = String(date.getDate()).padStart(2, "0");
  return `${y}-${m}-${d}`;
}
export function monthStart() {
  const date = new Date();
  const y = date.getFullYear();
  const m = String(date.getMonth() + 1).padStart(2, "0");
  return `${y}-${m}-01`;
}
export function energyName(type?: EnergyType) {
  return type ? energyInfo[type]?.name || type : "--";
}
export function metricName(metric?: EnergyAlertMetric) {
  return metric ? metricOptions.find(option => option.value === metric)?.label || metric : "--";
}
export function isAmountMetric(metric?: EnergyAlertMetric) {
  return !!metric && metric.endsWith("AMOUNT");
}