feat: 实现 OpenClaw Mission Control 仪表盘框架
- 创建 API Blueprint 模块结构 - 实现系统状态 API (CPU/内存/磁盘/进程) - 实现服务状态 API - 创建仪表盘页面模板 - 添加仪表盘 CSS 样式 - 添加仪表盘 JavaScript 交互 - 登录后自动跳转到仪表盘
This commit is contained in:
423
static/css/dashboard.css
Normal file
423
static/css/dashboard.css
Normal file
@@ -0,0 +1,423 @@
|
||||
/**
|
||||
* OpenClaw Mission Control - Dashboard Styles
|
||||
* 作者:小白 🐶
|
||||
*/
|
||||
|
||||
/* CSS 变量 */
|
||||
:root {
|
||||
--primary-color: #667eea;
|
||||
--primary-dark: #5a67d8;
|
||||
--success-color: #48bb78;
|
||||
--warning-color: #ed8936;
|
||||
--danger-color: #f56565;
|
||||
--bg-color: #f7fafc;
|
||||
--card-bg: #ffffff;
|
||||
--text-primary: #2d3748;
|
||||
--text-secondary: #718096;
|
||||
--border-color: #e2e8f0;
|
||||
--sidebar-width: 240px;
|
||||
--topnav-height: 60px;
|
||||
}
|
||||
|
||||
[data-theme="dark"] {
|
||||
--primary-color: #a78bfa;
|
||||
--primary-dark: #8b5cf6;
|
||||
--bg-color: #1a1a2e;
|
||||
--card-bg: #16213e;
|
||||
--text-primary: #e2e8f0;
|
||||
--text-secondary: #a0aec0;
|
||||
--border-color: #2d3748;
|
||||
}
|
||||
|
||||
/* 重置 */
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', sans-serif;
|
||||
background: var(--bg-color);
|
||||
color: var(--text-primary);
|
||||
min-height: 100vh;
|
||||
transition: background 0.3s ease, color 0.3s ease;
|
||||
}
|
||||
|
||||
/* 顶部导航 */
|
||||
.top-nav {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: var(--topnav-height);
|
||||
background: var(--card-bg);
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 0 20px;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.nav-brand {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.nav-brand .logo {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.nav-brand .title {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.nav-user {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.nav-user .username {
|
||||
color: var(--text-secondary);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.btn-logout {
|
||||
padding: 6px 12px;
|
||||
background: var(--danger-color);
|
||||
color: white;
|
||||
border-radius: 6px;
|
||||
text-decoration: none;
|
||||
font-size: 14px;
|
||||
transition: opacity 0.3s;
|
||||
}
|
||||
|
||||
.btn-logout:hover {
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
/* 主题按钮 */
|
||||
.theme-toggle {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 50%;
|
||||
border: none;
|
||||
background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
|
||||
color: white;
|
||||
font-size: 20px;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.theme-toggle:hover {
|
||||
transform: rotate(20deg) scale(1.1);
|
||||
}
|
||||
|
||||
/* 侧边栏 */
|
||||
.sidebar {
|
||||
position: fixed;
|
||||
top: var(--topnav-height);
|
||||
left: 0;
|
||||
bottom: 0;
|
||||
width: var(--sidebar-width);
|
||||
background: var(--card-bg);
|
||||
border-right: 1px solid var(--border-color);
|
||||
overflow-y: auto;
|
||||
padding: 20px 0;
|
||||
}
|
||||
|
||||
.sidebar-nav {
|
||||
padding: 0 10px;
|
||||
}
|
||||
|
||||
.nav-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 12px 15px;
|
||||
color: var(--text-secondary);
|
||||
text-decoration: none;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 5px;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.nav-item:hover {
|
||||
background: var(--bg-color);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.nav-item.active {
|
||||
background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.nav-item .icon {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.nav-item .text {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.quick-links {
|
||||
padding: 20px 15px;
|
||||
border-top: 1px solid var(--border-color);
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.quick-links .section-title {
|
||||
font-size: 12px;
|
||||
color: var(--text-secondary);
|
||||
text-transform: uppercase;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.link-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 8px 10px;
|
||||
color: var(--text-secondary);
|
||||
text-decoration: none;
|
||||
font-size: 13px;
|
||||
border-radius: 6px;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.link-item:hover {
|
||||
background: var(--bg-color);
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
/* 主内容区 */
|
||||
.main-content {
|
||||
margin-left: var(--sidebar-width);
|
||||
margin-top: var(--topnav-height);
|
||||
padding: 30px;
|
||||
min-height: calc(100vh - var(--topnav-height));
|
||||
}
|
||||
|
||||
.page {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.page.active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.page-title {
|
||||
font-size: 24px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 25px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
/* 状态卡片 */
|
||||
.stats-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
|
||||
gap: 20px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
background: var(--card-bg);
|
||||
border-radius: 12px;
|
||||
padding: 20px;
|
||||
border: 1px solid var(--border-color);
|
||||
transition: transform 0.3s ease, box-shadow 0.3s ease;
|
||||
}
|
||||
|
||||
.stat-card:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.stat-card .stat-icon {
|
||||
font-size: 32px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.stat-card .stat-label {
|
||||
font-size: 14px;
|
||||
color: var(--text-secondary);
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.stat-card .stat-value {
|
||||
font-size: 24px;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.stat-card .progress-bar {
|
||||
height: 6px;
|
||||
background: var(--border-color);
|
||||
border-radius: 3px;
|
||||
margin-top: 15px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.stat-card .progress {
|
||||
height: 100%;
|
||||
border-radius: 3px;
|
||||
transition: width 0.5s ease;
|
||||
}
|
||||
|
||||
.stat-card.cpu .progress { background: var(--primary-color); }
|
||||
.stat-card.memory .progress { background: var(--success-color); }
|
||||
.stat-card.disk .progress { background: var(--warning-color); }
|
||||
|
||||
/* 服务状态 */
|
||||
.section {
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 15px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.services-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.service-card {
|
||||
background: var(--card-bg);
|
||||
border-radius: 10px;
|
||||
padding: 15px;
|
||||
border: 1px solid var(--border-color);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.service-card .icon {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.service-card .info {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.service-card .name {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.service-card .port {
|
||||
font-size: 12px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.service-card .status-badge {
|
||||
padding: 3px 8px;
|
||||
border-radius: 12px;
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.status-badge.running {
|
||||
background: rgba(72, 187, 120, 0.2);
|
||||
color: var(--success-color);
|
||||
}
|
||||
|
||||
.status-badge.stopped {
|
||||
background: rgba(245, 101, 101, 0.2);
|
||||
color: var(--danger-color);
|
||||
}
|
||||
|
||||
/* 快捷操作 */
|
||||
.actions-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
background: var(--card-bg);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 10px;
|
||||
padding: 15px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.action-btn:hover {
|
||||
background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
|
||||
color: white;
|
||||
border-color: transparent;
|
||||
}
|
||||
|
||||
.action-btn .icon {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.action-btn span:last-child {
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* 开发中提示 */
|
||||
.coming-soon {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 60px 20px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.coming-soon .icon {
|
||||
font-size: 48px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.coming-soon p {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
/* 加载动画 */
|
||||
.loading {
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
/* 响应式 */
|
||||
@media (max-width: 768px) {
|
||||
.sidebar {
|
||||
width: 60px;
|
||||
padding: 10px 0;
|
||||
}
|
||||
|
||||
.sidebar .nav-item .text,
|
||||
.sidebar .quick-links {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.main-content {
|
||||
margin-left: 60px;
|
||||
padding: 20px;
|
||||
}
|
||||
}
|
||||
106
static/js/dashboard.js
Normal file
106
static/js/dashboard.js
Normal file
@@ -0,0 +1,106 @@
|
||||
/**
|
||||
* OpenClaw Mission Control - Dashboard JavaScript
|
||||
* 作者:小白 🐶
|
||||
*/
|
||||
|
||||
// 页面切换
|
||||
document.querySelectorAll('.nav-item').forEach(item => {
|
||||
item.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
// 移除所有活动状态
|
||||
document.querySelectorAll('.nav-item').forEach(i => i.classList.remove('active'));
|
||||
document.querySelectorAll('.page').forEach(p => p.classList.remove('active'));
|
||||
|
||||
// 添加当前活动状态
|
||||
item.classList.add('active');
|
||||
const pageId = 'page-' + item.dataset.page;
|
||||
document.getElementById(pageId).classList.add('active');
|
||||
});
|
||||
});
|
||||
|
||||
// 获取系统状态
|
||||
async function fetchStatus() {
|
||||
try {
|
||||
const response = await fetch('/api/status');
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
const data = result.data;
|
||||
|
||||
// 更新 CPU
|
||||
document.getElementById('cpu-percent').textContent = data.cpu.percent + '%';
|
||||
document.getElementById('cpu-progress').style.width = data.cpu.percent + '%';
|
||||
|
||||
// 更新内存
|
||||
document.getElementById('memory-value').textContent =
|
||||
`${data.memory.used} / ${data.memory.total} GB`;
|
||||
document.getElementById('memory-progress').style.width = data.memory.percent + '%';
|
||||
|
||||
// 更新磁盘
|
||||
document.getElementById('disk-value').textContent =
|
||||
`${data.disk.used} / ${data.disk.total} GB`;
|
||||
document.getElementById('disk-progress').style.width = data.disk.percent + '%';
|
||||
|
||||
// 更新进程数
|
||||
document.getElementById('process-count').textContent = data.process_count;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取状态失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取服务状态
|
||||
async function fetchServices() {
|
||||
try {
|
||||
const response = await fetch('/api/status/services');
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
const container = document.getElementById('services-grid');
|
||||
container.innerHTML = '';
|
||||
|
||||
const icons = {
|
||||
'Flask': '🌐',
|
||||
'思源笔记': '📝',
|
||||
'Gitea': '📦',
|
||||
'NocoDB': '📊',
|
||||
'Memory Viewer': '🧠'
|
||||
};
|
||||
|
||||
result.data.forEach(service => {
|
||||
const card = document.createElement('div');
|
||||
card.className = 'service-card';
|
||||
card.innerHTML = `
|
||||
<span class="icon">${icons[service.name] || '🔌'}</span>
|
||||
<div class="info">
|
||||
<div class="name">${service.name}</div>
|
||||
<div class="port">端口: ${service.port}</div>
|
||||
</div>
|
||||
<span class="status-badge ${service.status}">${
|
||||
service.status === 'running' ? '运行中' :
|
||||
service.status === 'stopped' ? '已停止' : '未知'
|
||||
}</span>
|
||||
`;
|
||||
container.appendChild(card);
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取服务状态失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 刷新状态
|
||||
function refreshStatus() {
|
||||
fetchStatus();
|
||||
fetchServices();
|
||||
}
|
||||
|
||||
// 初始化
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
fetchStatus();
|
||||
fetchServices();
|
||||
|
||||
// 每 30 秒自动刷新
|
||||
setInterval(fetchStatus, 30000);
|
||||
});
|
||||
Reference in New Issue
Block a user