mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-17 22:30:25 +08:00
访问日志增加更容易可视化的时间显示
This commit is contained in:
@@ -16,14 +16,16 @@ Tea.context(function () {
|
||||
.success(function (resp) {
|
||||
this.accessLogs = resp.data.accessLogs.concat(this.accessLogs)
|
||||
|
||||
// 添加区域信息
|
||||
this.accessLogs.forEach(function (accessLog) {
|
||||
if (typeof (resp.data.regions[accessLog.remoteAddr]) == "string") {
|
||||
accessLog.region = resp.data.regions[accessLog.remoteAddr]
|
||||
} else {
|
||||
accessLog.region = ""
|
||||
}
|
||||
})
|
||||
// 添加区域信息
|
||||
let that = this
|
||||
this.accessLogs.forEach(function (accessLog) {
|
||||
that.formatTime(accessLog)
|
||||
if (typeof (resp.data.regions[accessLog.remoteAddr]) == "string") {
|
||||
accessLog.region = resp.data.regions[accessLog.remoteAddr]
|
||||
} else {
|
||||
accessLog.region = ""
|
||||
}
|
||||
})
|
||||
|
||||
let max = 100
|
||||
if (this.accessLogs.length > max) {
|
||||
@@ -45,4 +47,18 @@ Tea.context(function () {
|
||||
}, 5000)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
this.formatTime = function (accessLog) {
|
||||
let elapsedSeconds = Math.ceil(new Date().getTime() / 1000) - accessLog.timestamp
|
||||
if (elapsedSeconds >= 0) {
|
||||
if (elapsedSeconds < 60) {
|
||||
accessLog.humanTime = elapsedSeconds + "秒前"
|
||||
} else if (elapsedSeconds < 3600) {
|
||||
accessLog.humanTime = Math.ceil(elapsedSeconds / 60) + "分钟前"
|
||||
} else if (elapsedSeconds < 3600 * 24) {
|
||||
accessLog.humanTime = Math.ceil(elapsedSeconds / 3600) + "小时前"
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user