File tree Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change 1
1
import { findAccountLogs } from "@/api/caravan/Login" ;
2
2
import { LoginFrequencyChart } from "@/components/Echarts" ;
3
+ import { getDateTimeFormat } from "@/utils/core" ;
3
4
import { Table } from "antd" ;
4
5
import dayjs from "dayjs" ;
5
6
import { useEffect , useState } from "react" ;
@@ -44,7 +45,7 @@ const LoginLog = () => {
44
45
title : "登录时间" ,
45
46
dataIndex : "created" ,
46
47
render : item => {
47
- return < span > { dayjs ( item ) . format ( "YYYY-MM-DD HH:mm" ) } </ span > ;
48
+ return < span > { getDateTimeFormat ( new Date ( item ) . valueOf ( ) ) } </ span > ;
48
49
}
49
50
}
50
51
] ;
Original file line number Diff line number Diff line change @@ -250,3 +250,42 @@ export const getMenuStructure = (menus: any[], parentUid: number = 0) => {
250
250
} ) ;
251
251
return newList . sort ( ( a , b ) => a . sort - b . sort ) ;
252
252
} ;
253
+
254
+ /* *
255
+ * 把传入的时间戳与当前时间比较,计算几分钟前、几小时前、几天前,以及几分钟后、几小时后、几天前后
256
+ * unixtime 需要计算的时间戳,保留到秒
257
+ * */
258
+ export const getDateTimeFormat = unixtime => {
259
+ const calcTime = typeof unixtime === "string" ? new Date ( unixtime ) . valueOf ( ) : unixtime ;
260
+ const currTime = new Date ( ) . valueOf ( ) ;
261
+ const time = currTime - calcTime ;
262
+
263
+ const value = Math . abs ( time / 1000 ) ;
264
+ // 少于一分钟
265
+ if ( value < 60 ) return "刚刚" ;
266
+
267
+ // 秒转分钟
268
+ const minuies = value / 60 ;
269
+ if ( minuies < 60 ) {
270
+ return Math . floor ( minuies ) + "分钟前" ;
271
+ }
272
+
273
+ // 秒转小时
274
+ const hours = value / 3600 ;
275
+ if ( hours < 24 ) {
276
+ return Math . floor ( hours ) + "小时前" ;
277
+ }
278
+ //秒转天数
279
+ const days = value / 3600 / 24 ;
280
+ if ( days < 30 ) {
281
+ return Math . floor ( days ) + "天前" ;
282
+ }
283
+ //秒转月
284
+ const months = value / 3600 / 24 / 30 ;
285
+ if ( months < 12 ) {
286
+ return Math . floor ( months ) + "月前" ;
287
+ }
288
+ //秒转年
289
+ const years = value / 3600 / 24 / 30 / 12 ;
290
+ return Math . floor ( years ) + "年前" ;
291
+ } ;
You can’t perform that action at this time.
0 commit comments