加入定时刷新功能
This commit is contained in:
@@ -17,6 +17,13 @@
|
||||
<el-option label="最近500行" :value="500"></el-option>
|
||||
<el-option label="最近1000行" :value="1000"></el-option>
|
||||
</el-select>
|
||||
<el-select v-model="refreshInterval" size="small" style="margin-left: 20px; width: 100px;" @change="handleRefreshInterval">
|
||||
<el-option label="1秒" :value="1"></el-option>
|
||||
<el-option label="3秒" :value="3"></el-option>
|
||||
<el-option label="5秒" :value="5"></el-option>
|
||||
<el-option label="10秒" :value="10"></el-option>
|
||||
<el-option label="60秒" :value="60"></el-option>
|
||||
</el-select>
|
||||
<el-button style="float: right; padding: 3px 0" type="text" @click="loadLogs">刷新</el-button>
|
||||
</div>
|
||||
|
||||
@@ -43,12 +50,17 @@
|
||||
logType: 'info',
|
||||
logLines: 100,
|
||||
logContent: [],
|
||||
refreshInterval: 0, // 新增,定时刷新间隔(秒),0为不自动刷新
|
||||
refreshTimer: null, // 新增,定时器句柄
|
||||
currentView: '9' // 设置当前菜单项
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.loadLogs();
|
||||
},
|
||||
beforeDestroy() {
|
||||
this.clearRefreshTimer();
|
||||
},
|
||||
methods: {
|
||||
loadLogs() {
|
||||
this.loading = true;
|
||||
@@ -56,6 +68,13 @@
|
||||
.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('加载日志失败');
|
||||
}
|
||||
@@ -67,6 +86,20 @@
|
||||
.finally(() => {
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
handleRefreshInterval() {
|
||||
this.clearRefreshTimer();
|
||||
if (this.refreshInterval > 0) {
|
||||
this.refreshTimer = setInterval(() => {
|
||||
this.loadLogs();
|
||||
}, this.refreshInterval * 1000);
|
||||
}
|
||||
},
|
||||
clearRefreshTimer() {
|
||||
if (this.refreshTimer) {
|
||||
clearInterval(this.refreshTimer);
|
||||
this.refreshTimer = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user