1. 修改了跳转逻辑

2. 增加了首页banner栏性能监控
This commit is contained in:
2026-01-21 09:42:38 +08:00
parent 861a4f4833
commit 5be838a74e
5 changed files with 140 additions and 2 deletions

View File

@@ -230,8 +230,26 @@ register_blueprints(app)
# ============ 健康检查 ============
@app.route('/api/health', methods=['GET'])
def health_check():
"""健康检查接口"""
return jsonify({'status': 'ok', 'code': 0})
"""健康检查接口,返回系统监控数据"""
import psutil
try:
cpu_percent = int(psutil.cpu_percent(interval=None))
memory = psutil.virtual_memory()
memory_percent = int(memory.percent)
disk = psutil.disk_usage('/')
disk_percent = int(disk.percent)
return jsonify({
'status': 'ok',
'code': 0,
'data': {
'cpu_percent': cpu_percent,
'memory_percent': memory_percent,
'disk_percent': disk_percent
}
})
except Exception as e:
return jsonify({'status': 'error', 'code': 1, 'message': str(e)})
# ============ 通用 CRUD 操作 ============

25
web/index.html Normal file
View File

@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>跳转中...</title>
</head>
<body>
<p>正在检查登录状态...</p>
<script>
// 会话超时检查5分钟
const SESSION_TIMEOUT = 5 * 60 * 1000; // 5分钟
const loginTime = localStorage.getItem('loginTime');
if (!loginTime || (Date.now() - parseInt(loginTime)) > SESSION_TIMEOUT) {
// 会话过期,跳转登录页
localStorage.removeItem('loginTime');
localStorage.removeItem('username');
window.location.href = 'pages/login.html';
} else {
// 会话有效,跳转主页
localStorage.setItem('loginTime', Date.now());
window.location.href = 'pages/main.html';
}
</script>
</body>
</html>

View File

@@ -159,6 +159,9 @@
if (result.code === 0) {
errorMsg.classList.add('hidden');
// 保存登录时间戳5分钟超时
localStorage.setItem('loginTime', Date.now());
localStorage.setItem('username', username);
window.location.href = 'main.html';
} else {
errorMsg.textContent = result.message || '账号或密码错误';

View File

@@ -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': {

View File

@@ -341,6 +341,25 @@
</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 基础地址
const getApiBase = () => {
const protocol = window.location.protocol;