优化log显示效果
This commit is contained in:
@@ -1,166 +1,284 @@
|
|||||||
{% extends "base.html" %}
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh-CN">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>{% block title %}机器人管理后台{% endblock %}</title>
|
||||||
|
<!-- 添加favicon -->
|
||||||
|
<link rel="icon" href="/static/favicon.ico" type="image/x-icon">
|
||||||
|
<link rel="shortcut icon" href="/static/favicon.ico" type="image/x-icon">
|
||||||
|
<!-- Element UI CSS -->
|
||||||
|
<link rel="stylesheet" href="/static/css/element-ui/theme-chalk/index.min.css">
|
||||||
|
<!-- 图表库 -->
|
||||||
|
<script src="/static/js/chart.js"></script>
|
||||||
|
<!-- Vue.js -->
|
||||||
|
<script src="/static/js/vue.js"></script>
|
||||||
|
<!-- Element UI JS -->
|
||||||
|
<script src="/static/js/element-ui/index.min.js"></script>
|
||||||
|
<!-- Axios -->
|
||||||
|
<script src="/static/js/axios.min.js"></script>
|
||||||
|
|
||||||
{% block title %}微信日志查看{% endblock %}
|
<style>
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
|
||||||
|
}
|
||||||
|
.app-container {
|
||||||
|
height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
.header {
|
||||||
|
background-color: #006af5;
|
||||||
|
color: white;
|
||||||
|
padding: 0 20px;
|
||||||
|
height: 60px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
.header-left {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
.header-logo {
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
.main-container {
|
||||||
|
display: flex;
|
||||||
|
flex: 1;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
.sidebar {
|
||||||
|
width: 200px;
|
||||||
|
background-color: #545c64;
|
||||||
|
height: 100%;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
.content {
|
||||||
|
flex: 1;
|
||||||
|
padding: 20px;
|
||||||
|
overflow-y: auto;
|
||||||
|
background-color: #f0f2f5;
|
||||||
|
display: flex; /* 添加Flex布局 */
|
||||||
|
flex-direction: column; /* 确保子元素垂直排列 */
|
||||||
|
}
|
||||||
|
.el-menu {
|
||||||
|
border-right: none;
|
||||||
|
}
|
||||||
|
.chart-container {
|
||||||
|
background-color: white;
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 4px;
|
||||||
|
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
.stats-card {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
/* 添加退出登录按钮样式 */
|
||||||
|
.logout-btn {
|
||||||
|
color: white;
|
||||||
|
cursor: pointer;
|
||||||
|
margin-left: 15px;
|
||||||
|
}
|
||||||
|
.header-right {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
.user-info {
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
{% block head %}{% endblock %}
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="app" class="app-container">
|
||||||
|
<header class="header">
|
||||||
|
<div class="header-left">
|
||||||
|
<img src="/static/logo.png" alt="Logo" class="header-logo">
|
||||||
|
<h2>机器人管理后台</h2>
|
||||||
|
</div>
|
||||||
|
<!-- 添加退出登录按钮 -->
|
||||||
|
<div class="header-right">
|
||||||
|
<span class="user-info">管理员</span>
|
||||||
|
<el-button type="text" class="logout-btn" @click="logout">
|
||||||
|
<i class="el-icon-switch-button"></i> 退出登录
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
{% block content %}
|
<div class="main-container">
|
||||||
<div class="log-page-container">
|
<!-- 左侧菜单 -->
|
||||||
<el-card class="log-card">
|
<div class="sidebar">
|
||||||
<div slot="header" class="clearfix">
|
<el-menu
|
||||||
<span>日志查看</span>
|
:default-active="currentView"
|
||||||
<el-radio-group v-model="logType" size="small" style="margin-left: 20px;" @change="loadLogs">
|
class="el-menu-vertical-demo"
|
||||||
<el-radio-button label="info">信息日志</el-radio-button>
|
background-color="#545c64"
|
||||||
<el-radio-button label="error">错误日志</el-radio-button>
|
text-color="#fff"
|
||||||
<el-radio-button label="debug">调试日志</el-radio-button>
|
active-text-color="#ffd04b"
|
||||||
</el-radio-group>
|
@select="handleSelect">
|
||||||
<el-select v-model="logLines" size="small" style="margin-left: 20px;" @change="loadLogs">
|
<el-menu-item index="1">
|
||||||
<el-option label="最近100行" :value="100"></el-option>
|
<i class="el-icon-s-home"></i>
|
||||||
<el-option label="最近500行" :value="500"></el-option>
|
<span slot="title">首页概览</span>
|
||||||
<el-option label="最近1000行" :value="1000"></el-option>
|
</el-menu-item>
|
||||||
|
<el-menu-item index="2">
|
||||||
|
<i class="el-icon-s-grid"></i>
|
||||||
|
<span slot="title">插件统计</span>
|
||||||
|
</el-menu-item>
|
||||||
|
<el-menu-item index="3">
|
||||||
|
<i class="el-icon-user"></i>
|
||||||
|
<span slot="title">用户统计</span>
|
||||||
|
</el-menu-item>
|
||||||
|
<el-menu-item index="4">
|
||||||
|
<i class="el-icon-s-cooperation"></i>
|
||||||
|
<span slot="title">群组统计</span>
|
||||||
|
</el-menu-item>
|
||||||
|
<el-menu-item index="5">
|
||||||
|
<i class="el-icon-warning"></i>
|
||||||
|
<span slot="title">错误日志</span>
|
||||||
|
</el-menu-item>
|
||||||
|
|
||||||
|
<!-- 在左侧菜单中添加群机器人管理选项 -->
|
||||||
|
<!-- 找到el-menu标签内的菜单项列表,添加以下内容 -->
|
||||||
|
<el-menu-item index="6">
|
||||||
|
<i class="el-icon-setting"></i>
|
||||||
|
<span slot="title">群机器人</span>
|
||||||
|
</el-menu-item>
|
||||||
|
<!-- 在左侧菜单中添加消息列表选项 -->
|
||||||
|
<el-menu-item index="7">
|
||||||
|
<i class="el-icon-chat-line-square"></i>
|
||||||
|
<span slot="title">消息列表</span>
|
||||||
|
</el-menu-item>
|
||||||
|
<!-- 运行日志 -->
|
||||||
|
<el-menu-item index="9">
|
||||||
|
<i class="el-icon-document"></i>
|
||||||
|
<span slot="title">运行日志</span>
|
||||||
|
</el-menu-item>
|
||||||
|
<!-- 在导航菜单中添加通讯录管理入口 -->
|
||||||
|
<el-menu-item index="10">
|
||||||
|
<i class="el-icon-notebook-1"></i>
|
||||||
|
<span slot="title">通讯录</span>
|
||||||
|
</el-menu-item>
|
||||||
|
<!-- 在导航菜单中添加插件管理选项 -->
|
||||||
|
<el-menu-item index="11">
|
||||||
|
<i class="el-icon-s-tools"></i>
|
||||||
|
<span slot="title">插件管理</span>
|
||||||
|
</el-menu-item>
|
||||||
|
<!-- 在导航菜单中添加虚拟群组管理 -->
|
||||||
|
<el-menu-item index="12">
|
||||||
|
<i class="el-icon-connection"></i>
|
||||||
|
<span slot="title">虚拟群组</span>
|
||||||
|
</el-menu-item>
|
||||||
|
<!-- 添加接口文档菜单项 -->
|
||||||
|
<el-menu-item index="13">
|
||||||
|
<i class="el-icon-document"></i>
|
||||||
|
<span slot="title">接口文档</span>
|
||||||
|
</el-menu-item>
|
||||||
|
<el-menu-item index="14">
|
||||||
|
<i class="el-icon-cpu"></i>
|
||||||
|
<span slot="title">服务器监控</span>
|
||||||
|
</el-menu-item>
|
||||||
|
</el-menu>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 右侧内容区 -->
|
||||||
|
<div class="content">
|
||||||
|
<!-- 时间范围选择器 - 只在特定页面显示 -->
|
||||||
|
<el-row :gutter="20" style="margin-bottom: 20px;" v-if="showTimeRangeSelector">
|
||||||
|
<el-col :span="24">
|
||||||
|
<el-card shadow="hover">
|
||||||
|
<el-form :inline="true" size="small">
|
||||||
|
<el-form-item label="统计时间范围">
|
||||||
|
<el-select v-model="timeRange" @change="loadData">
|
||||||
|
<el-option label="最近7天" value="7"></el-option>
|
||||||
|
<el-option label="最近30天" value="30"></el-option>
|
||||||
|
<el-option label="最近90天" value="90"></el-option>
|
||||||
</el-select>
|
</el-select>
|
||||||
<el-select v-model="refreshInterval" size="small" style="margin-left: 20px; width: 100px;" @change="handleRefreshInterval">
|
</el-form-item>
|
||||||
<el-option label="手动" :value="0"></el-option>
|
<el-form-item>
|
||||||
<el-option label="1秒" :value="1"></el-option>
|
<el-button type="primary" @click="loadData">刷新数据</el-button>
|
||||||
<el-option label="3秒" :value="3"></el-option>
|
</el-form-item>
|
||||||
<el-option label="5秒" :value="5"></el-option>
|
</el-form>
|
||||||
<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>
|
|
||||||
|
|
||||||
<div v-loading="loading" class="log-content-wrapper">
|
|
||||||
<div v-if="logContent && logContent.length > 0" class="log-content">
|
|
||||||
<pre>{% raw %}{{ logContent.join('') }}{% endraw %}</pre>
|
|
||||||
</div>
|
|
||||||
<div v-else class="empty-log">
|
|
||||||
<el-empty description="暂无日志内容"></el-empty>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</el-card>
|
</el-card>
|
||||||
</div>
|
</el-col>
|
||||||
{% endblock %}
|
</el-row>
|
||||||
|
|
||||||
{% block scripts %}
|
<!-- 内容区域 -->
|
||||||
|
{% block content %}{% endblock %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 基础 Vue 实例 -->
|
||||||
<script>
|
<script>
|
||||||
new Vue({
|
const baseApp = {
|
||||||
el: '#app',
|
|
||||||
mixins: [baseApp],
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
loading: false,
|
currentView: '1',
|
||||||
logType: 'info',
|
timeRange: '7',
|
||||||
logLines: 100,
|
charts: {},
|
||||||
logContent: [],
|
// 添加一个标志,用于控制时间范围选择器的显示
|
||||||
refreshInterval: 0,
|
|
||||||
refreshTimer: null,
|
|
||||||
currentView: '9',
|
|
||||||
showTimeRangeSelector: false
|
showTimeRangeSelector: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
created() {
|
||||||
this.loadLogs();
|
// 根据当前页面路径决定是否显示时间范围选择器
|
||||||
},
|
const path = window.location.pathname;
|
||||||
beforeDestroy() {
|
// 只在统计相关页面显示时间范围选择器
|
||||||
this.clearRefreshTimer();
|
this.showTimeRangeSelector = ['/', '/plugins', '/users', '/groups','/robot','/errors'].includes(path);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
loadLogs() {
|
handleSelect(key, keyPath) {
|
||||||
this.loading = true;
|
this.currentView = key;
|
||||||
axios.get(`/api/wx_logs?type=${this.logType}&lines=${this.logLines}`)
|
// 添加页面跳转逻辑
|
||||||
.then(response => {
|
const routes = {
|
||||||
if (response.data.success) {
|
'1': '/',
|
||||||
this.logContent = response.data.data.content || [];
|
'2': '/plugins',
|
||||||
this.$nextTick(() => {
|
'3': '/users',
|
||||||
const logDiv = this.$el.querySelector('.log-content');
|
'4': '/groups',
|
||||||
if (logDiv) {
|
'5': '/errors',
|
||||||
logDiv.scrollTop = logDiv.scrollHeight;
|
'6': '/robot',
|
||||||
console.log('log-content scrollHeight:', logDiv.scrollHeight, 'clientHeight:', logDiv.clientHeight);
|
'7': '/messages',
|
||||||
}
|
'9': '/wx_logs',
|
||||||
});
|
'10': '/contacts',
|
||||||
} else {
|
'11': '/plugins_manage',
|
||||||
this.$message.error('加载日志失败');
|
'12': '/virtual_group',
|
||||||
}
|
'13':'/api_docs',
|
||||||
})
|
'14':'/system_status'
|
||||||
.catch(error => {
|
};
|
||||||
console.error('加载日志出错:', error);
|
|
||||||
this.$message.error('加载日志出错');
|
// 如果当前不在对应页面,则跳转
|
||||||
})
|
const currentPath = window.location.pathname;
|
||||||
.finally(() => {
|
const targetPath = routes[key];
|
||||||
this.loading = false;
|
if (currentPath !== targetPath && targetPath !== undefined) {
|
||||||
});
|
window.location.href = targetPath;
|
||||||
},
|
|
||||||
handleRefreshInterval() {
|
|
||||||
this.clearRefreshTimer();
|
|
||||||
if (this.refreshInterval > 0) {
|
|
||||||
this.refreshTimer = setInterval(() => {
|
|
||||||
this.loadLogs();
|
|
||||||
}, this.refreshInterval * 1000);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
clearRefreshTimer() {
|
loadData() {
|
||||||
if (this.refreshTimer) {
|
// 由子组件实现
|
||||||
clearInterval(this.refreshTimer);
|
},
|
||||||
this.refreshTimer = null;
|
// 添加退出登录方法
|
||||||
}
|
logout() {
|
||||||
}
|
// 显示确认对话框
|
||||||
}
|
this.$confirm('确认退出登录吗?', '提示', {
|
||||||
|
confirmButtonText: '确定',
|
||||||
|
cancelButtonText: '取消',
|
||||||
|
type: 'warning'
|
||||||
|
}).then(() => {
|
||||||
|
// 用户点击确定,跳转到登出页面
|
||||||
|
window.location.href = '/logout';
|
||||||
|
}).catch(() => {
|
||||||
|
// 用户点击取消,不做任何操作
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
{% block scripts %}{% endblock %}
|
||||||
.log-page-container {
|
</body>
|
||||||
height: 100%;
|
</html>
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
|
|
||||||
.log-card {
|
|
||||||
flex: 1;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
margin: 0;
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.el-card__body {
|
|
||||||
flex: 1;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
.log-content-wrapper {
|
|
||||||
flex: 1;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
.log-content {
|
|
||||||
flex: 1;
|
|
||||||
overflow-y: auto !important;
|
|
||||||
overflow-x: auto !important;
|
|
||||||
background-color: #f5f5f5;
|
|
||||||
padding: 10px;
|
|
||||||
border-radius: 4px;
|
|
||||||
box-sizing: border-box;
|
|
||||||
min-height: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.log-content pre {
|
|
||||||
margin: 0;
|
|
||||||
white-space: pre-wrap;
|
|
||||||
word-break: break-all;
|
|
||||||
font-family: monospace;
|
|
||||||
line-height: 1.5;
|
|
||||||
}
|
|
||||||
|
|
||||||
.empty-log {
|
|
||||||
flex: 1;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
{% endblock %}
|
|
||||||
Reference in New Issue
Block a user