访问日志增加更容易可视化的时间显示

This commit is contained in:
刘祥超
2021-07-12 18:06:43 +08:00
parent b8295e5cfc
commit 40f32c7cf9
3 changed files with 43 additions and 9 deletions

View File

@@ -156,6 +156,10 @@ Tea.context(function () {
this.$post(".wafLogs")
.success(function (resp) {
if (resp.data.accessLogs != null) {
let that = this
resp.data.accessLogs.forEach(function (v) {
that.formatTime(v)
})
this.accessLogs = resp.data.accessLogs
}
})
@@ -163,4 +167,17 @@ Tea.context(function () {
this.$delay(this.reloadAccessLogs, 10000)
})
}
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) + "小时前"
}
}
}
})