From 920dee6265d102d01423cfc503ba86f2839fd5c7 Mon Sep 17 00:00:00 2001 From: liuwei Date: Wed, 28 May 2025 17:10:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96log=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/dashboard/templates/wx_logs.html | 208 ++++++++++++++++--------- 1 file changed, 134 insertions(+), 74 deletions(-) diff --git a/admin/dashboard/templates/wx_logs.html b/admin/dashboard/templates/wx_logs.html index e8a6d95..4fb0687 100644 --- a/admin/dashboard/templates/wx_logs.html +++ b/admin/dashboard/templates/wx_logs.html @@ -5,32 +5,44 @@ {% block content %}
-
- 日志查看 - - 信息日志 - 错误日志 - 调试日志 - - - - - - - - - - - - - - - 刷新 -
+ -
-
-
{% raw %}{{ logContent.join('') }}{% endraw %}
+
+
+ + 自动滚动到底部 +
+
+
+ {{ formatTimestamp(log.timestamp) }} + {{ log.level }} + {{ log.message }} +
@@ -51,9 +63,12 @@ logType: 'info', logLines: 100, logContent: [], - refreshInterval: 0, // 新增,定时刷新间隔(秒),0为不自动刷新 - refreshTimer: null, // 新增,定时器句柄 - currentView: '9' // 设置当前菜单项 + filteredLogs: [], + searchQuery: '', + autoScroll: true, + refreshInterval: 0, + refreshTimer: null, + currentView: '9' } }, mounted() { @@ -63,30 +78,52 @@ this.clearRefreshTimer(); }, methods: { - loadLogs() { + async loadLogs() { this.loading = true; - axios.get(`/api/wx_logs?type=${this.logType}&lines=${this.logLines}`) - .then(response => { - if (response.data.success) { - this.logContent = response.data.data.content || []; - // 日志内容更新后自动滚动到底部 - this.$nextTick(() => { - const logDiv = this.$el.querySelector('.log-content'); - if (logDiv) { - logDiv.scrollTop = logDiv.scrollHeight; - } - }); - } else { - this.$message.error('加载日志失败'); + try { + const response = await axios.get(`/api/wx_logs?type=${this.logType}&lines=${this.logLines}`); + if (response.data.success) { + this.logContent = response.data.data.content || []; + this.filterLogs(); + this.scrollToBottom(); + } else { + this.$message.error('加载日志失败'); + } + } catch (error) { + console.error('加载日志出错:', error); + this.$message.error('加载日志出错'); + } finally { + this.loading = false; + } + }, + filterLogs() { + if (!this.searchQuery) { + this.filteredLogs = this.logContent; + } else { + const query = this.searchQuery.toLowerCase(); + this.filteredLogs = this.logContent.filter(log => + log.message.toLowerCase().includes(query) || + log.level.toLowerCase().includes(query) || + log.timestamp.toLowerCase().includes(query) + ); + } + this.$nextTick(() => this.scrollToBottom()); + }, + formatTimestamp(timestamp) { + return new Date(timestamp).toLocaleString('zh-CN', { + year: 'numeric', month: '2-digit', day: '2-digit', + hour: '2-digit', minute: '2-digit', second: '2-digit' + }); + }, + scrollToBottom() { + if (this.autoScroll) { + this.$nextTick(() => { + const logDiv = this.$el.querySelector('.log-content'); + if (logDiv) { + logDiv.scrollTop = logDiv.scrollHeight; } - }) - .catch(error => { - console.error('加载日志出错:', error); - this.$message.error('加载日志出错'); - }) - .finally(() => { - this.loading = false; }); + } }, handleRefreshInterval() { this.clearRefreshTimer(); @@ -106,30 +143,53 @@ }); - {% endblock %} \ No newline at end of file