From bedae250abd5640e68e772ae733bb7930822f56a Mon Sep 17 00:00:00 2001 From: liuwei Date: Wed, 28 May 2025 17:18:07 +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 | 226 ++++++++----------------- 1 file changed, 71 insertions(+), 155 deletions(-) diff --git a/admin/dashboard/templates/wx_logs.html b/admin/dashboard/templates/wx_logs.html index 321d37d..480712a 100644 --- a/admin/dashboard/templates/wx_logs.html +++ b/admin/dashboard/templates/wx_logs.html @@ -5,46 +5,31 @@ {% block content %}
- - -
-
- - 自动滚动到底部 -
-
- {% raw %} -
- {{ formatTimestamp(log.timestamp) }} - {{ log.level }} - {{ log.message }} -
- {% endraw %} +
+ 日志查看 + + 信息日志 + 错误日志 + 调试日志 + + + + + + + + + + + + + + 刷新 +
+ +
+
+
{% raw %}{{ logContent.join('') }}{% endraw %}
@@ -65,12 +50,9 @@ logType: 'info', logLines: 100, logContent: [], - filteredLogs: [], - searchQuery: '', - autoScroll: true, - refreshInterval: 0, - refreshTimer: null, - currentView: '9' + refreshInterval: 0, // 新增,定时刷新间隔(秒),0为不自动刷新 + refreshTimer: null, // 新增,定时器句柄 + currentView: '9' // 设置当前菜单项 } }, mounted() { @@ -80,73 +62,30 @@ this.clearRefreshTimer(); }, methods: { - async loadLogs() { + loadLogs() { this.loading = true; - try { - const response = await axios.get(`/api/wx_logs?type=${this.logType}&lines=${this.logLines}`); - if (response.data.success) { - // 解析文本日志行为对象数组 - this.logContent = this.parseLogLines(response.data.data.content || []); - this.filterLogs(); - this.scrollToBottom(); - } else { - this.$message.error('加载日志失败'); - } - } catch (error) { - console.error('加载日志出错:', error); - this.$message.error('加载日志出错'); - } finally { - this.loading = false; - } - }, - parseLogLines(lines) { - return lines.map(line => { - // 解析日志行,格式如:2025-05-28 17:10:04.758 | INFO | module:func:line - message - const parts = line.split(' | '); - if (parts.length < 4) { - return { timestamp: '', level: '', message: line }; // 格式不正确时保留原始行 - } - const [timestamp, level, , message] = parts; - return { - timestamp: timestamp.trim(), - level: level.trim(), - message: message.trim() - }; - }).filter(log => log.timestamp && log.level && log.message); // 过滤无效日志 - }, - filterLogs() { - if (!this.searchQuery) { - this.filteredLogs = this.logContent; - } else { - const query = this.searchQuery.toLowerCase(); - this.filteredLogs = this.logContent.filter(log => - (log.message && log.message.toLowerCase().includes(query)) || - (log.level && log.level.toLowerCase().includes(query)) || - (log.timestamp && log.timestamp.toLowerCase().includes(query)) - ); - } - this.$nextTick(() => this.scrollToBottom()); - }, - formatTimestamp(timestamp) { - if (!timestamp) return ''; - try { - return new Date(timestamp).toLocaleString('zh-CN', { - year: 'numeric', month: '2-digit', day: '2-digit', - hour: '2-digit', minute: '2-digit', second: '2-digit' - }); - } catch (e) { - return timestamp; // 解析失败时返回原始时间戳 - } - }, - scrollToBottom() { - if (this.autoScroll) { - this.$nextTick(() => { - const logDiv = this.$el.querySelector('.log-content'); - if (logDiv) { - logDiv.scrollTop = logDiv.scrollHeight; + 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('加载日志失败'); } + }) + .catch(error => { + console.error('加载日志出错:', error); + this.$message.error('加载日志出错'); + }) + .finally(() => { + this.loading = false; }); - } }, handleRefreshInterval() { this.clearRefreshTimer(); @@ -166,53 +105,30 @@ }); - {% endblock %} \ No newline at end of file