diff --git a/web/public/js/components/server/http-access-log-box.js b/web/public/js/components/server/http-access-log-box.js index 62b5e645..939085b5 100644 --- a/web/public/js/components/server/http-access-log-box.js +++ b/web/public/js/components/server/http-access-log-box.js @@ -9,6 +9,7 @@ Vue.component("http-access-log-box", { accessLog.scheme = "wss" } } + return { accessLog: accessLog } @@ -48,7 +49,7 @@ Vue.component("http-access-log-box", { } }, template: `
- [{{accessLog.region}}] {{accessLog.remoteAddr}} [{{accessLog.timeLocal}}] "{{accessLog.requestMethod}} {{accessLog.scheme}}://{{accessLog.host}}{{accessLog.requestURI}} {{accessLog.proto}}" {{accessLog.status}} cache hit waf {{accessLog.attrs['waf.action']}} - 耗时:{{formatCost(accessLog.requestTime)}} ms + [{{accessLog.region}}] {{accessLog.remoteAddr}} [{{accessLog.timeLocal}}] "{{accessLog.requestMethod}} {{accessLog.scheme}}://{{accessLog.host}}{{accessLog.requestURI}} {{accessLog.proto}}" {{accessLog.status}} cache hit waf {{accessLog.attrs['waf.action']}} - 耗时:{{formatCost(accessLog.requestTime)}} ms   ({{accessLog.humanTime}})  
` }) \ No newline at end of file diff --git a/web/views/@default/dashboard/boards/waf.js b/web/views/@default/dashboard/boards/waf.js index 65b81cef..bc58b94c 100644 --- a/web/views/@default/dashboard/boards/waf.js +++ b/web/views/@default/dashboard/boards/waf.js @@ -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) + "小时前" + } + } + } }) \ No newline at end of file diff --git a/web/views/@default/servers/server/log/index.js b/web/views/@default/servers/server/log/index.js index 6e5a392b..bd2e6f1b 100644 --- a/web/views/@default/servers/server/log/index.js +++ b/web/views/@default/servers/server/log/index.js @@ -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) + "小时前" + } + } + } }) \ No newline at end of file