refactor(analytics): 将时间戳存储从字符串改为数字类型
统一使用数字类型存储时间戳,提高时间处理效率和一致性。修改相关类型定义和格式化函数以支持新旧数据格式。
This commit is contained in:
@@ -97,7 +97,7 @@ export type VisitPageItem = {
|
||||
postTitle: string | null;
|
||||
postUrl: string | null;
|
||||
pv: number;
|
||||
lastVisitAt: string | null;
|
||||
lastVisitAt: number | null;
|
||||
};
|
||||
|
||||
export type VisitPagesResponse = {
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user