From cd6c1423246b6f34c5c742b271a44a6d109e19e4 Mon Sep 17 00:00:00 2001 From: Supra4E8C Date: Wed, 17 Dec 2025 18:03:25 +0800 Subject: [PATCH] fix: fix log page timestamp display and optimize AuthFiles layout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add formatUnixTimestamp utility to auto-detect timestamp precision (s/ms/μs/ns) - Fix incorrect file modification time display in logs page - Remove fixed height constraint from AuthFilesPage model list --- src/pages/AuthFilesPage.module.scss | 2 -- src/pages/LogsPage.tsx | 3 ++- src/utils/format.ts | 31 +++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/pages/AuthFilesPage.module.scss b/src/pages/AuthFilesPage.module.scss index fc8807f..6f09678 100644 --- a/src/pages/AuthFilesPage.module.scss +++ b/src/pages/AuthFilesPage.module.scss @@ -417,8 +417,6 @@ display: flex; flex-direction: column; gap: $spacing-sm; - max-height: 400px; - overflow-y: auto; } .modelItem { diff --git a/src/pages/LogsPage.tsx b/src/pages/LogsPage.tsx index eab0cc5..e044fd1 100644 --- a/src/pages/LogsPage.tsx +++ b/src/pages/LogsPage.tsx @@ -7,6 +7,7 @@ import { ToggleSwitch } from '@/components/ui/ToggleSwitch'; import { IconDownload, IconRefreshCw, IconTimer, IconTrash2 } from '@/components/ui/icons'; import { useNotificationStore, useAuthStore } from '@/stores'; import { logsApi } from '@/services/api/logs'; +import { formatUnixTimestamp } from '@/utils/format'; import styles from './LogsPage.module.scss'; interface ErrorLogItem { @@ -629,7 +630,7 @@ export function LogsPage() {
{item.name}
{item.size ? `${(item.size / 1024).toFixed(1)} KB` : ''}{' '} - {item.modified ? new Date(item.modified).toLocaleString() : ''} + {item.modified ? formatUnixTimestamp(item.modified) : ''}
diff --git a/src/utils/format.ts b/src/utils/format.ts index 153a31e..109a9e6 100644 --- a/src/utils/format.ts +++ b/src/utils/format.ts @@ -52,6 +52,37 @@ export function formatDateTime(date: string | Date): string { }); } +/** + * 将 Unix 时间戳(秒/毫秒/微秒/纳秒)格式化为本地时间字符串 + */ +export function formatUnixTimestamp(value: unknown, locale?: string): string { + if (value === null || value === undefined || value === '') return ''; + + const asNumber = typeof value === 'number' ? value : Number(value); + const date = (() => { + if (!Number.isFinite(asNumber) || Number.isNaN(asNumber)) { + return new Date(String(value)); + } + + const abs = Math.abs(asNumber); + + // 秒:常见 10 位(~1e9) + if (abs < 1e11) return new Date(asNumber * 1000); + + // 毫秒:常见 13 位(~1e12) + if (abs < 1e14) return new Date(asNumber); + + // 微秒:常见 16 位(~1e15) + if (abs < 1e17) return new Date(Math.round(asNumber / 1000)); + + // 纳秒:常见 19 位(~1e18) + return new Date(Math.round(asNumber / 1e6)); + })(); + + if (Number.isNaN(date.getTime())) return ''; + return locale ? date.toLocaleString(locale) : date.toLocaleString(); +} + /** * 格式化数字(添加千位分隔符) */