import dayjs from "dayjs"; /** 展示:2026-01-23 11:39:09 */ export function formatDateTime(value) { if (value == null || value === "") { return "-"; } const d = dayjs(value); return d.isValid() ? d.format("YYYY-MM-DD HH:mm:ss") : String(value); } /** 展示:2026-01-23 */ export function formatDate(value) { if (value == null || value === "") { return "-"; } const d = dayjs(value); return d.isValid() ? d.format("YYYY-MM-DD") : String(value); } /** 提交 API:日期 */ export function toApiDate(value) { if (value == null || value === "") { return undefined; } if (typeof value === "string") { return value.length > 10 ? value.slice(0, 10) : value; } const d = dayjs(value); return d.isValid() ? d.format("YYYY-MM-DD") : undefined; } /** 提交 API:日期时间 */ export function toApiDateTime(value) { if (value == null || value === "") { return undefined; } if (typeof value === "string") { return value; } const d = dayjs(value); return d.isValid() ? d.format("YYYY-MM-DDTHH:mm:ss") : undefined; } /** DatePicker 回显 */ export function toDayjs(value) { if (value == null || value === "") { return undefined; } const d = dayjs(value); return d.isValid() ? d : undefined; }