From cedd5722b3799f663d94b9b0f458e3a695c859b0 Mon Sep 17 00:00:00 2001 From: liuwei Date: Thu, 8 May 2025 11:13:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5debug=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E6=9F=A5=E7=9C=8B=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/dashboard/templates/wx_logs.html | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/admin/dashboard/templates/wx_logs.html b/admin/dashboard/templates/wx_logs.html index d2d87e5..56db50e 100644 --- a/admin/dashboard/templates/wx_logs.html +++ b/admin/dashboard/templates/wx_logs.html @@ -43,6 +43,7 @@ logType: 'info', logLines: 100, logContent: [], + logContentHtml: '', // 新增 currentView: '9' // 设置当前菜单项 } }, @@ -56,17 +57,39 @@ .then(response => { if (response.data.success) { this.logContent = response.data.data.content || []; + // 处理为带颜色的HTML + this.logContentHtml = this.logContent.map(line => { + if (line.includes('ERROR')) { + return `${this.escapeHtml(line)}`; + } else if (line.includes('WARNING') || line.includes('WARN')) { + return `${this.escapeHtml(line)}`; + } else if (line.includes('DEBUG')) { + return `${this.escapeHtml(line)}`; + } else if (line.includes('INFO')) { + return `${this.escapeHtml(line)}`; + } else { + return `${this.escapeHtml(line)}`; + } + }).join(''); } else { this.$message.error('加载日志失败'); + this.logContentHtml = ''; } }) .catch(error => { console.error('加载日志出错:', error); this.$message.error('加载日志出错'); + this.logContentHtml = ''; }) .finally(() => { this.loading = false; }); + }, + escapeHtml(text) { + // 防止XSS + return text.replace(/[<>&"]/g, function(c) { + return {'<':'<','>':'>','&':'&','"':'"'}[c]; + }); } } });