diff --git a/web/src/components/comment/comment-item.tsx b/web/src/components/comment/comment-item.tsx index 8bfbc65..e639961 100644 --- a/web/src/components/comment/comment-item.tsx +++ b/web/src/components/comment/comment-item.tsx @@ -51,6 +51,8 @@ export function CommentItem( const [replies, setReplies] = useState([]); const [repliesLoaded, setRepliesLoaded] = useState(false); + console.log(comment) + const handleToggleLike = () => { if (!canClickLike) { return; @@ -175,6 +177,7 @@ export function CommentItem( unitI18n: { secondsAgo: commonT("secondsAgo"), minutesAgo: commonT("minutesAgo"), hoursAgo: commonT("hoursAgo"), daysAgo: commonT("daysAgo") } })} {commentState.createdAt !== commentState.updatedAt && + (new Date(commentState.updatedAt).getTime() - new Date(commentState.createdAt).getTime()) > 10000 && {t("edit_at", { time: formatDateTime({ dateTimeString: commentState.updatedAt, diff --git a/web/src/types/datetime.ts b/web/src/types/datetime.ts new file mode 100644 index 0000000..e69de29 diff --git a/web/src/utils/common/datetime.ts b/web/src/utils/common/datetime.ts index 87c8a26..1771d59 100644 --- a/web/src/utils/common/datetime.ts +++ b/web/src/utils/common/datetime.ts @@ -40,13 +40,17 @@ export function formatDateTime({ return getAgoString(diff, unitI18n); } + if (now.getFullYear() !== date.getFullYear()) { + // 不同年,显示完整日期时间 + return date.toLocaleString(locale, { + year: 'numeric', + month: 'short', + day: 'numeric', + }); + } + return date.toLocaleString(locale, { - year: 'numeric', month: 'short', day: 'numeric', - hour: '2-digit', - minute: '2-digit', - second: '2-digit', - hour12: false, }); } \ No newline at end of file