mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-02-18 10:40:50 +08:00
fix: fix log page timestamp display and optimize AuthFiles layout
- 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
This commit is contained in:
@@ -417,8 +417,6 @@
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: $spacing-sm;
|
||||
max-height: 400px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.modelItem {
|
||||
|
||||
@@ -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() {
|
||||
<div className="item-title">{item.name}</div>
|
||||
<div className="item-subtitle">
|
||||
{item.size ? `${(item.size / 1024).toFixed(1)} KB` : ''}{' '}
|
||||
{item.modified ? new Date(item.modified).toLocaleString() : ''}
|
||||
{item.modified ? formatUnixTimestamp(item.modified) : ''}
|
||||
</div>
|
||||
</div>
|
||||
<div className="item-actions">
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化数字(添加千位分隔符)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user