From 874418ac47d61d9a0c6c72a37caa401b5c5712e3 Mon Sep 17 00:00:00 2001 From: Montia37 Date: Wed, 13 Aug 2025 18:32:16 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E5=88=B0?= =?UTF-8?q?=E6=9C=9F=E4=BF=A1=E6=81=AF=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/sections/NodeCard.tsx | 10 ++------- src/components/sections/NodeListItem.tsx | 10 ++------- src/hooks/useNodeCommons.ts | 26 ++++++++++++++++++------ 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/components/sections/NodeCard.tsx b/src/components/sections/NodeCard.tsx index 6d10adb..050f46b 100644 --- a/src/components/sections/NodeCard.tsx +++ b/src/components/sections/NodeCard.tsx @@ -35,7 +35,7 @@ export const NodeCard = ({ node }: NodeCardProps) => { swapUsage, diskUsage, load, - daysLeft, + expired_at, } = useNodeCommons(node); const getProgressBarClass = (percentage: number) => { @@ -166,13 +166,7 @@ export const NodeCard = ({ node }: NodeCardProps) => {
到期 -
- {daysLeft !== null && daysLeft > 36500 - ? "长期" - : node.expired_at - ? new Date(node.expired_at).toLocaleDateString() - : "N/A"} -
+
{expired_at}
diff --git a/src/components/sections/NodeListItem.tsx b/src/components/sections/NodeListItem.tsx index d5890e6..8924fab 100644 --- a/src/components/sections/NodeListItem.tsx +++ b/src/components/sections/NodeListItem.tsx @@ -20,7 +20,7 @@ export const NodeListItem = ({ node }: NodeListItemProps) => { swapUsage, diskUsage, load, - daysLeft, + expired_at, } = useNodeCommons(node); return ( @@ -40,13 +40,7 @@ export const NodeListItem = ({ node }: NodeListItemProps) => {
到期: -
- {daysLeft !== null && daysLeft > 36500 - ? "长期" - : node.expired_at - ? new Date(node.expired_at).toLocaleDateString() - : "N/A"} -
+
{expired_at}
diff --git a/src/hooks/useNodeCommons.ts b/src/hooks/useNodeCommons.ts index a41a7cb..4a6a04c 100644 --- a/src/hooks/useNodeCommons.ts +++ b/src/hooks/useNodeCommons.ts @@ -39,13 +39,27 @@ export const useNodeCommons = (node: NodeWithStatus) => { ) : null; + let daysLeftTag = null; + if (daysLeft !== null) { + if (daysLeft < 0) { + daysLeftTag = "已过期"; + } else if (daysLeft < 36500) { + daysLeftTag = `余 ${daysLeft} 天`; + } else { + daysLeftTag = "长期"; + } + } + + const expired_at = + daysLeft !== null && daysLeft > 36500 + ? "长期" + : node.expired_at + ? new Date(node.expired_at).toLocaleDateString() + : "N/A"; + const tagList = [ price, - `${daysLeft && daysLeft < 0 ? "已过期" : ""}${ - daysLeft && daysLeft >= 0 && daysLeft < 36500 - ? "余 " + daysLeft + " 天" - : "" - }`, + ...(daysLeftTag ? [daysLeftTag] : []), ...(typeof node.tags === "string" ? node.tags .split(";") @@ -63,6 +77,6 @@ export const useNodeCommons = (node: NodeWithStatus) => { swapUsage, diskUsage, load, - daysLeft, + expired_at, }; };