1. 修改了跳转逻辑
2. 增加了首页banner栏性能监控
This commit is contained in:
@@ -258,6 +258,22 @@
|
||||
</button>
|
||||
</div>
|
||||
<div class="flex items-center space-x-4">
|
||||
<!-- 系统性能监控 -->
|
||||
<a href="?page=config" class="flex items-center space-x-4 text-xs text-gray-500 hover:text-primary transition-colors">
|
||||
<div class="flex items-center" title="CPU使用率">
|
||||
<i class="fa fa-microchip mr-1 text-blue-500"></i>
|
||||
<span id="cpuUsage">--</span>%
|
||||
</div>
|
||||
<div class="flex items-center" title="内存使用率">
|
||||
<i class="fa fa-database mr-1 text-green-500"></i>
|
||||
<span id="memUsage">--</span>%
|
||||
</div>
|
||||
<div class="flex items-center" title="磁盘使用率">
|
||||
<i class="fa fa-hdd-o mr-1 text-orange-500"></i>
|
||||
<span id="diskUsage">--</span>%
|
||||
</div>
|
||||
</a>
|
||||
<div class="h-6 w-px bg-gray-200"></div>
|
||||
<div class="relative group">
|
||||
<img src="https://picsum.photos/id/1005/32/32" class="w-8 h-8 rounded-full cursor-pointer" alt="用户头像">
|
||||
<div class="absolute right-0 top-full pt-2 hidden group-hover:block z-50">
|
||||
@@ -281,6 +297,28 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// 会话超时检查(5分钟)
|
||||
const SESSION_TIMEOUT = 5 * 60 * 1000; // 5分钟
|
||||
function checkSession() {
|
||||
const loginTime = localStorage.getItem('loginTime');
|
||||
if (!loginTime || (Date.now() - parseInt(loginTime)) > SESSION_TIMEOUT) {
|
||||
// 会话过期,清除并跳转到登录页
|
||||
localStorage.removeItem('loginTime');
|
||||
localStorage.removeItem('username');
|
||||
window.location.href = 'login.html';
|
||||
return false;
|
||||
}
|
||||
// 更新登录时间(用户有活动时续期)
|
||||
localStorage.setItem('loginTime', Date.now());
|
||||
return true;
|
||||
}
|
||||
|
||||
// 页面加载时检查会话
|
||||
if (!checkSession()) {
|
||||
// 阻止页面渲染
|
||||
document.body.innerHTML = '';
|
||||
}
|
||||
|
||||
// 动态获取 API 基础地址(根据当前访问的 IP 自动调整)
|
||||
const getApiBase = () => {
|
||||
const protocol = window.location.protocol;
|
||||
@@ -289,6 +327,41 @@
|
||||
};
|
||||
const API_BASE = getApiBase();
|
||||
|
||||
// 获取系统性能监控数据
|
||||
async function fetchSystemMetrics() {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/health`);
|
||||
const result = await response.json();
|
||||
if (result.code === 0 && result.data) {
|
||||
const data = result.data;
|
||||
// 更新CPU使用率
|
||||
const cpuEl = document.getElementById('cpuUsage');
|
||||
if (cpuEl && data.cpu_percent !== undefined) {
|
||||
cpuEl.textContent = data.cpu_percent;
|
||||
cpuEl.className = data.cpu_percent > 80 ? 'text-red-500 font-medium' : '';
|
||||
}
|
||||
// 更新内存使用率
|
||||
const memEl = document.getElementById('memUsage');
|
||||
if (memEl && data.memory_percent !== undefined) {
|
||||
memEl.textContent = data.memory_percent;
|
||||
memEl.className = data.memory_percent > 80 ? 'text-red-500 font-medium' : '';
|
||||
}
|
||||
// 更新磁盘使用率
|
||||
const diskEl = document.getElementById('diskUsage');
|
||||
if (diskEl && data.disk_percent !== undefined) {
|
||||
diskEl.textContent = data.disk_percent;
|
||||
diskEl.className = data.disk_percent > 80 ? 'text-red-500 font-medium' : '';
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取系统监控数据失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 页面加载时获取监控数据,并每5秒刷新
|
||||
fetchSystemMetrics();
|
||||
setInterval(fetchSystemMetrics, 5000);
|
||||
|
||||
// 各功能模块的表格配置
|
||||
const tableConfigs = {
|
||||
'fine-tune': {
|
||||
|
||||
Reference in New Issue
Block a user