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, }; };