From e3e338499584364d68a8b27a00fd8248d2a38b2d Mon Sep 17 00:00:00 2001 From: Snowykami Date: Wed, 24 Sep 2025 09:54:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=97=A5=E6=9C=9F?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E4=B8=8D=E5=90=8C=E5=B9=B4=E4=BB=BD=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E5=AE=8C=E6=95=B4=E6=97=A5=E6=9C=9F=EF=BC=9B=E5=9C=A8=E8=AF=84?= =?UTF-8?q?=E8=AE=BA=E9=A1=B9=E4=B8=AD=E6=B7=BB=E5=8A=A0=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E6=97=A5=E5=BF=97Close=20#18?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/components/comment/comment-item.tsx | 3 +++ web/src/types/datetime.ts | 0 web/src/utils/common/datetime.ts | 14 +++++++++----- 3 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 web/src/types/datetime.ts 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