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");
|
}
|