ui creation

This commit is contained in:
Первов Артем
2026-06-17 09:46:52 +03:00
commit 2c4aef1185
41 changed files with 6251 additions and 0 deletions

46
src/utils/format.ts Normal file
View File

@@ -0,0 +1,46 @@
/** Форматирует числовое значение показателя для карточек и мини-плиток. */
export function formatNumber(value: number): string {
if (!Number.isFinite(value)) {
return '—';
}
return new Intl.NumberFormat('ru-RU', {
maximumFractionDigits: Math.abs(value) >= 100 ? 1 : 3,
}).format(value);
}
/** Приводит дату/время к короткому русскому формату для операторского интерфейса. */
export function formatDateTime(value: string | number | Date): string {
const date = new Date(value);
if (Number.isNaN(date.getTime())) {
return '—';
}
return new Intl.DateTimeFormat('ru-RU', {
day: '2-digit',
month: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
}).format(date);
}
/** Конвертирует Date в формат, который ожидает input[type="datetime-local"]. */
export function toInputDateTimeValue(date: Date): string {
/** Дополняет часть даты ведущим нулем для стабильного input-формата. */
const pad = (part: number) => String(part).padStart(2, '0');
return [
`${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`,
`${pad(date.getHours())}:${pad(date.getMinutes())}`,
].join('T');
}
/** Преобразует значение datetime-local в ISO-строку для API-запросов. */
export function toIsoFromInput(value: string): string | undefined {
if (!value) {
return undefined;
}
const date = new Date(value);
return Number.isNaN(date.getTime()) ? undefined : date.toISOString();
}

25
src/utils/metricStatus.ts Normal file
View File

@@ -0,0 +1,25 @@
import type { CurrentItem } from '../api/cloud';
export type MetricStatus = 'normal' | 'warning' | 'critical';
export type MetricStatusInfo = {
status: MetricStatus;
label: string;
ageSeconds: number;
};
/** Классифицирует показатель по свежести данных до подключения реальных аварийных правил. */
export function getMetricStatus(item: CurrentItem, now = Date.now()): MetricStatusInfo {
const measuredAt = new Date(item.time).getTime();
const ageSeconds = Number.isFinite(measuredAt) ? Math.max(0, Math.round((now - measuredAt) / 1000)) : Number.POSITIVE_INFINITY;
if (ageSeconds > 300) {
return { status: 'critical', label: 'нет связи', ageSeconds };
}
if (ageSeconds > 30) {
return { status: 'warning', label: 'устарело', ageSeconds };
}
return { status: 'normal', label: 'норма', ageSeconds };
}