From 672ea932010438293dea42e0095e3c97c75115a4 Mon Sep 17 00:00:00 2001 From: liuwei Date: Thu, 25 Dec 2025 15:55:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=97=A5=E5=BF=97=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E4=B8=8E=E4=BC=A0=E8=BE=93=E6=95=88=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/dashboard/templates/wx_logs.html | 48 +++++++++++++++++++++----- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/admin/dashboard/templates/wx_logs.html b/admin/dashboard/templates/wx_logs.html index 76adc92..d2bdade 100644 --- a/admin/dashboard/templates/wx_logs.html +++ b/admin/dashboard/templates/wx_logs.html @@ -30,7 +30,7 @@
-
{% raw %}{{ logContent.join('') }}{% endraw %}
+

             
@@ -51,30 +51,60 @@ logType: 'info', logLines: 100, logContent: [], + logText: '', refreshInterval: 0, refreshTimer: null, currentView: '9', - showTimeRangeSelector: false + showTimeRangeSelector: false, + cancelSource: null, + isAutoScroll: true } }, mounted() { this.loadLogs(); + this.$nextTick(() => { + const logDiv = this.$el.querySelector('.log-content'); + if (logDiv) { + logDiv.addEventListener('scroll', () => { + const nearBottom = (logDiv.scrollHeight - logDiv.scrollTop - logDiv.clientHeight) < 50; + this.isAutoScroll = nearBottom; + }); + } + }); }, beforeDestroy() { this.clearRefreshTimer(); + if (this.cancelSource) { + this.cancelSource.cancel('component destroyed'); + this.cancelSource = null; + } }, methods: { loadLogs() { this.loading = true; - axios.get(`/api/wx_logs?type=${this.logType}&lines=${this.logLines}`) + if (this.cancelSource) { + this.cancelSource.cancel('new request'); + } + this.cancelSource = axios.CancelToken.source(); + axios.get(`/api/wx_logs`, { + params: { type: this.logType, lines: this.logLines }, + headers: { 'Accept-Encoding': 'gzip' }, + cancelToken: this.cancelSource.token + }) .then(response => { if (response.data.success) { this.logContent = response.data.data.content || []; + this.logText = this.logContent.join(''); this.$nextTick(() => { const logDiv = this.$el.querySelector('.log-content'); + const pre = this.$refs.logPre; + if (pre) { + pre.textContent = this.logText; + } if (logDiv) { - logDiv.scrollTop = logDiv.scrollHeight; - console.log('log-content scrollHeight:', logDiv.scrollHeight, 'clientHeight:', logDiv.clientHeight); + if (this.isAutoScroll) { + logDiv.scrollTop = logDiv.scrollHeight; + } } }); } else { @@ -82,8 +112,10 @@ } }) .catch(error => { - console.error('加载日志出错:', error); - this.$message.error('加载日志出错'); + if (!axios.isCancel(error)) { + console.error('加载日志出错:', error); + this.$message.error('加载日志出错'); + } }) .finally(() => { this.loading = false; @@ -163,4 +195,4 @@ overflow: hidden; } -{% endblock %} \ No newline at end of file +{% endblock %}