feat(webui): add safety confirms and local-time rendering; support install.sh -ui

This commit is contained in:
lpf
2026-03-04 14:39:46 +08:00
parent 09c06786a4
commit ccf2ed4703
9 changed files with 252 additions and 49 deletions

49
webui/src/utils/time.ts Normal file
View File

@@ -0,0 +1,49 @@
type DateLike = string | number | Date | null | undefined;
function parseDateLike(value: DateLike): Date | null {
if (value == null) return null;
if (value instanceof Date) {
return Number.isNaN(value.getTime()) ? null : value;
}
if (typeof value === 'number') {
const d = new Date(value);
return Number.isNaN(d.getTime()) ? null : d;
}
const s = String(value).trim();
if (!s) return null;
if (/^\d+$/.test(s)) {
const n = Number(s);
const ms = n > 1e12 ? n : n * 1000;
const d = new Date(ms);
return Number.isNaN(d.getTime()) ? null : d;
}
const d = new Date(s);
return Number.isNaN(d.getTime()) ? null : d;
}
export function formatLocalDateTime(value: DateLike, fallback = '-'): string {
const d = parseDateLike(value);
if (!d) {
const raw = value == null ? '' : String(value).trim();
return raw || fallback;
}
return d.toLocaleString();
}
export function formatLocalTime(value: DateLike, fallback = '--:--:--'): string {
const d = parseDateLike(value);
if (!d) {
const raw = value == null ? '' : String(value).trim();
return raw || fallback;
}
return d.toLocaleTimeString();
}
export function localDateInputValue(base = new Date()): string {
const d = new Date(base.getTime());
d.setMinutes(d.getMinutes() - d.getTimezoneOffset());
return d.toISOString().slice(0, 10);
}