帮助中心数据实现动态渲染

This commit is contained in:
Eamon-meng
2026-06-11 16:30:24 +08:00
parent 99039b6622
commit 7947fc48a2
10 changed files with 287 additions and 97 deletions

21
src/lib/utils/date.ts Normal file
View File

@@ -0,0 +1,21 @@
export function formatDate(
dateStr?: string | null,
format: string = 'YYYY-MM-DD',
fallback: string = '-',
): string {
if (!dateStr) return fallback
const date = new Date(dateStr)
if (isNaN(date.getTime())) return fallback
const map: Record<string, string | number> = {
YYYY: date.getFullYear(),
MM: String(date.getMonth() + 1).padStart(2, '0'),
DD: String(date.getDate()).padStart(2, '0'),
HH: String(date.getHours()).padStart(2, '0'),
mm: String(date.getMinutes()).padStart(2, '0'),
ss: String(date.getSeconds()).padStart(2, '0'),
}
return format.replace(/YYYY|MM|DD|HH|mm|ss/g, matched => String(map[matched]))
}