refactor(analytics): 将时间戳存储从字符串改为数字类型

统一使用数字类型存储时间戳,提高时间处理效率和一致性。修改相关类型定义和格式化函数以支持新旧数据格式。
This commit is contained in:
anghunk
2026-01-21 22:47:31 +08:00
parent fe0773a091
commit 705cf0e3c8
4 changed files with 29 additions and 14 deletions

View File

@@ -97,7 +97,7 @@ export type VisitPageItem = {
postTitle: string | null;
postUrl: string | null;
pv: number;
lastVisitAt: string | null;
lastVisitAt: number | null;
};
export type VisitPagesResponse = {

View File

@@ -127,13 +127,27 @@ function showToast(msg: string, type: "success" | "error" = "success") {
}, 2000);
}
function formatTime(value: string | null): string {
function formatTime(value: string | number | null | undefined): string {
if (!value) {
return "-";
}
const date = new Date(value);
let date: Date;
if (typeof value === "number") {
date = new Date(value);
} else {
const trimmed = value.trim();
if (!trimmed) {
return "-";
}
if (/^\d+$/.test(trimmed)) {
const ts = Number(trimmed);
date = new Date(ts);
} else {
date = new Date(trimmed);
}
}
if (Number.isNaN(date.getTime())) {
return value;
return "-";
}
const y = date.getFullYear();
const m = String(date.getMonth() + 1).padStart(2, "0");