Files
admin-front/src/utils/format.ts
T
2026-10-01 22:52:19 +03:00

41 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import dayjs from 'dayjs'
import utc from 'dayjs/plugin/utc'
import type { CvProfile, SetStatus, Verdict } from '@/api/types'
dayjs.extend(utc)
/** Бэкенд хранит время в UTC без зоны — форматируем как UTC. */
export function formatUtc(iso: string | null | undefined): string {
if (!iso) return '—'
const d = dayjs.utc(iso)
return d.isValid() ? d.format('DD.MM.YYYY HH:mm:ss') : iso
}
export function formatConfidence(confidence: number | null | undefined): string {
if (confidence == null) return '—'
return confidence.toFixed(2)
}
export const verdictMeta: Record<Verdict, { label: string; color: string }> = {
match: { label: 'Совпадение', color: 'green' },
uncertain: { label: 'Неопределённо', color: 'orange' },
no_match: { label: 'Нет совпадения', color: 'red' },
}
export const cvProfileMeta: Record<CvProfile, { label: string; color: string }> = {
facade: { label: 'Фасад', color: 'blue' },
monument: { label: 'Памятник', color: 'purple' },
repetitive: { label: 'Повторяющийся объект', color: 'cyan' },
}
export const setStatusMeta: Record<SetStatus, { label: string; color: string }> = {
DRAFT: { label: 'Черновик', color: 'default' },
ACTIVE: { label: 'Активен', color: 'green' },
ARCHIVED: { label: 'В архиве', color: 'default' },
}
export const cvProfileOptions = (Object.keys(cvProfileMeta) as CvProfile[]).map((value) => ({
value,
label: cvProfileMeta[value].label,
}))