lushdog@outlook.com 1 тиждень тому
батько
коміт
b96d4c26e1
1 змінених файлів з 22 додано та 14 видалено
  1. 22 14
      src/app/components/DataTable.tsx

+ 22 - 14
src/app/components/DataTable.tsx

@@ -414,6 +414,26 @@ function DataTableContent() {
 		// eslint-disable-next-line react-hooks/exhaustive-deps
 	}, [])
 
+	const renderPositionAgeMs = (text: string) => {
+		const rawAgeMs = Number(text)
+		const ageMs = Number.isFinite(rawAgeMs) ? Math.max(0, rawAgeMs) : 0
+		const days = Math.floor(ageMs / 86400000)
+		const hours = Math.floor((ageMs % 86400000) / 3600000)
+		const minutes = Math.floor((ageMs % 3600000) / 60000)
+
+		return (
+			<span
+				className="font-mono text-sm"
+				style={{
+					color: days > 0 ? '#2a9d61' : '#FF0000',
+				}}
+			>
+				{days > 0 ? `${days}天/` : ''}
+				{hours > 0 || days > 0 ? `${hours}小时/` : ''}
+				{minutes}分钟
+			</span>
+		)
+	}
 	const columns = [
 		{
 			title: '创建地址',
@@ -540,13 +560,7 @@ function DataTableContent() {
 			sorter: (a: TableData, b: TableData) => {
 				return Number(a.positionAgeMs) - Number(b.positionAgeMs)
 			},
-			render: (text: string) => {
-				return (
-					<span className="font-bold text-lg">
-						{Math.floor(Number(text) / 1000 / 60 / 60)} 小时
-					</span>
-				)
-			},
+			render: renderPositionAgeMs,
 		},
 		{
 			title: '操作',
@@ -795,13 +809,7 @@ function DataTableContent() {
 			title: '创建时间',
 			dataIndex: 'positionAgeMs',
 			key: 'positionAgeMs',
-			render: (text: string) => {
-				return (
-					<span className="font-bold text-base">
-						{Math.floor(Number(text) / 1000 / 60 / 60)} 小时
-					</span>
-				)
-			},
+			render: renderPositionAgeMs,
 		},
 		{
 			title: '状态',