feat: 添加龙虾详情页面功能
- 新建 LobsterDetail 组件,显示龙虾详细信息
- 添加 React Router 路由配置 (/lobster/:id)
- Dashboard 添加详情按钮,支持跳转到详情页
- 详情页功能:
* 基本信息展示(名称、专长、端口、容器、工作区)
* 运行状态指示器(带脉冲动画)
* 快速操作(查看记忆、访问服务、复制地址)
* 运行统计卡片
- 修复 index.html 缺少 root 挂载点问题
- 添加一键重启脚本 restart.sh
- 更新任务跟踪文档
🦸 北极星指引方向,飞行侠展翅飞翔
This commit is contained in:
17172
code/frontend/package-lock.json
generated
Normal file
17172
code/frontend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -6,6 +6,7 @@
|
||||
"dependencies": {
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-router-dom": "^6.20.0",
|
||||
"react-scripts": "5.0.1",
|
||||
"axios": "^1.6.0"
|
||||
},
|
||||
|
||||
@@ -4,506 +4,8 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>🦞 龙虾舰队监控中心</title>
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
background: linear-gradient(135deg, #1a365d 0%, #2c5282 100%);
|
||||
min-height: 100vh;
|
||||
padding: 20px;
|
||||
color: #fff;
|
||||
}
|
||||
.container { max-width: 1400px; margin: 0 auto; }
|
||||
|
||||
.header {
|
||||
text-align: center;
|
||||
padding: 30px 0;
|
||||
border-bottom: 2px solid rgba(255,255,255,0.1);
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
.header h1 { font-size: 2.5em; margin-bottom: 10px; }
|
||||
.header p { opacity: 0.8; font-size: 1.1em; }
|
||||
|
||||
.overview {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
gap: 20px;
|
||||
margin-bottom: 40px;
|
||||
}
|
||||
.stat-card {
|
||||
background: rgba(255,255,255,0.1);
|
||||
border-radius: 12px;
|
||||
padding: 25px;
|
||||
text-align: center;
|
||||
backdrop-filter: blur(10px);
|
||||
}
|
||||
.stat-value { font-size: 2.5em; font-weight: bold; margin-bottom: 5px; }
|
||||
.stat-label { opacity: 0.8; font-size: 0.95em; }
|
||||
|
||||
.lobsters {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
|
||||
gap: 25px;
|
||||
}
|
||||
.lobster-card {
|
||||
background: rgba(255,255,255,0.95);
|
||||
border-radius: 16px;
|
||||
padding: 25px;
|
||||
color: #1a365d;
|
||||
transition: transform 0.3s, box-shadow 0.3s;
|
||||
cursor: pointer;
|
||||
}
|
||||
.lobster-card:hover {
|
||||
transform: translateY(-5px);
|
||||
box-shadow: 0 10px 30px rgba(0,0,0,0.3);
|
||||
}
|
||||
.lobster-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.lobster-name { font-size: 1.5em; font-weight: bold; }
|
||||
.status-indicator {
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
border-radius: 50%;
|
||||
display: inline-block;
|
||||
animation: pulse 2s infinite;
|
||||
}
|
||||
@keyframes pulse {
|
||||
0%, 100% { opacity: 1; }
|
||||
50% { opacity: 0.5; }
|
||||
}
|
||||
.status-healthy { background: #48bb78; }
|
||||
.status-error { background: #f56565; }
|
||||
|
||||
.lobster-info { margin-bottom: 15px; }
|
||||
.info-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 8px 0;
|
||||
border-bottom: 1px solid rgba(0,0,0,0.05);
|
||||
}
|
||||
.info-label { opacity: 0.7; font-size: 0.9em; }
|
||||
.info-value { font-weight: 500; }
|
||||
|
||||
.lobster-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-top: 20px;
|
||||
padding-top: 15px;
|
||||
border-top: 2px solid rgba(0,0,0,0.1);
|
||||
}
|
||||
.action-btn {
|
||||
flex: 1;
|
||||
padding: 10px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
font-weight: 500;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
.btn-memory { background: #9f7aea; color: white; }
|
||||
.btn-memory:hover { background: #805ad5; }
|
||||
|
||||
.refresh-time { margin-top: 10px; font-size: 0.9em; opacity: 0.6; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>🦞 龙虾舰队监控中心</h1>
|
||||
<p>实时监控龙虾舰队运行状态</p>
|
||||
<div class="refresh-time">最后更新:<span id="lastUpdate">-</span></div>
|
||||
</div>
|
||||
|
||||
<div class="overview">
|
||||
<div class="stat-card">
|
||||
<div class="stat-value" id="totalLobsters">6</div>
|
||||
<div class="stat-label">龙虾总数</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-value" id="healthyCount" style="color: #48bb78;">-</div>
|
||||
<div class="stat-label">健康运行</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-value" id="errorCount" style="color: #f56565;">-</div>
|
||||
<div class="stat-label">异常</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="lobsters" id="lobsterGrid">
|
||||
<!-- 龙虾卡片将通过 JS 动态生成 -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// 龙虾配置
|
||||
const lobsters = [
|
||||
{ id: 1, name: '飞行侠', emoji: '🦸', port: 18789, specialty: '主力/通用' },
|
||||
{ id: 2, name: '道童', emoji: '☯️', port: 18889, specialty: '道德经注解' },
|
||||
{ id: 3, name: '墨子', emoji: '🔧', port: 18689, specialty: '代码专家' },
|
||||
{ id: 4, name: '织网者', emoji: '🕸️', port: 18589, specialty: '网站制作' },
|
||||
{ id: 5, name: '费曼', emoji: '⚛️', port: 18989, specialty: '物理研究' },
|
||||
{ id: 6, name: '守望者', emoji: '👁️', port: 18080, specialty: '舰队监控' },
|
||||
];
|
||||
|
||||
// 当前打开的记忆弹窗
|
||||
let currentMemoryModal = null;
|
||||
|
||||
// 打开记忆弹窗
|
||||
function openMemory(lobster) {
|
||||
if (currentMemoryModal) {
|
||||
currentMemoryModal.remove();
|
||||
}
|
||||
|
||||
const modal = document.createElement('div');
|
||||
modal.className = 'memory-modal-container';
|
||||
document.body.appendChild(modal);
|
||||
|
||||
// 加载记忆组件
|
||||
loadMemoryComponent(lobster, modal);
|
||||
}
|
||||
|
||||
async function loadMemoryComponent(lobster, container) {
|
||||
try {
|
||||
// 获取有日记的日期
|
||||
const datesResp = await fetch(`http://localhost:8000/api/lobsters/${lobster.id}/memory/dates/`);
|
||||
const datesData = await datesResp.json();
|
||||
const dates = datesData.dates || [];
|
||||
|
||||
// 默认显示最新日记
|
||||
let selectedDate = dates.length > 0 ? dates[0] : '';
|
||||
let content = '这一天还没有日记';
|
||||
|
||||
if (selectedDate) {
|
||||
const contentResp = await fetch(`http://localhost:8000/api/lobsters/${lobster.id}/memory/${selectedDate}/`);
|
||||
const contentData = await contentResp.json();
|
||||
content = contentData.content || '日记内容为空';
|
||||
}
|
||||
|
||||
renderMemoryModal(lobster, dates, selectedDate, content, container);
|
||||
} catch (error) {
|
||||
container.innerHTML = `<div class="memory-error">加载失败:${error.message}</div>`;
|
||||
}
|
||||
}
|
||||
|
||||
function renderMemoryModal(lobster, dates, selectedDate, content, container) {
|
||||
const today = new Date();
|
||||
const year = today.getFullYear();
|
||||
const month = today.getMonth();
|
||||
|
||||
container.innerHTML = `
|
||||
<div class="memory-overlay" onclick="closeMemory()">
|
||||
<div class="memory-dialog" onclick="event.stopPropagation()">
|
||||
<div class="memory-header">
|
||||
<h2>📔 ${lobster.emoji} ${lobster.name} - 工作日记</h2>
|
||||
<button class="memory-close" onclick="closeMemory()">×</button>
|
||||
</div>
|
||||
|
||||
<div class="memory-body">
|
||||
<div class="memory-content-area">
|
||||
${content ? `
|
||||
<div class="memory-date-title">📅 ${selectedDate}</div>
|
||||
<pre>${escapeHtml(content)}</pre>
|
||||
` : '<div class="memory-empty">这一天还没有日记</div>'}
|
||||
</div>
|
||||
|
||||
<div class="memory-calendar">
|
||||
<div class="calendar-nav">
|
||||
<button onclick="changeMonth(-1)">◀</button>
|
||||
<span>${year}年 ${month + 1}月</span>
|
||||
<button onclick="changeMonth(1)">▶</button>
|
||||
</div>
|
||||
<div class="calendar-grid">
|
||||
${['日', '一', '二', '三', '四', '五', '六'].map(d => `<div class="cal-weekday">${d}</div>`).join('')}
|
||||
${renderCalendarDays(year, month, dates, selectedDate, lobster.id)}
|
||||
</div>
|
||||
<div class="calendar-legend">
|
||||
<span class="legend-item"><span class="legend-dot has-memory"></span>有日记</span>
|
||||
<span class="legend-item"><span class="legend-dot no-memory"></span>无日记</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.memory-overlay {
|
||||
position: fixed;
|
||||
top: 0; left: 0; right: 0; bottom: 0;
|
||||
background: rgba(0,0,0,0.7);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 1000;
|
||||
}
|
||||
.memory-dialog {
|
||||
background: white;
|
||||
border-radius: 16px;
|
||||
width: 90%;
|
||||
max-width: 1000px;
|
||||
max-height: 90vh;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.memory-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 20px;
|
||||
border-bottom: 1px solid #e2e8f0;
|
||||
}
|
||||
.memory-header h2 {
|
||||
color: #1a365d;
|
||||
margin: 0;
|
||||
}
|
||||
.memory-close {
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 2em;
|
||||
cursor: pointer;
|
||||
color: #718096;
|
||||
}
|
||||
.memory-body {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 350px;
|
||||
gap: 20px;
|
||||
padding: 20px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.memory-content-area {
|
||||
background: #f7fafc;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
overflow-y: auto;
|
||||
max-height: 600px;
|
||||
}
|
||||
.memory-date-title {
|
||||
color: #553c9a;
|
||||
margin-bottom: 15px;
|
||||
font-size: 1.2em;
|
||||
}
|
||||
.memory-content-area pre {
|
||||
white-space: pre-wrap;
|
||||
word-wrap: break-word;
|
||||
font-family: 'Courier New', monospace;
|
||||
font-size: 0.9em;
|
||||
color: #2d3748;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.memory-empty {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100%;
|
||||
color: #a0aec0;
|
||||
}
|
||||
.memory-calendar {
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 8px;
|
||||
padding: 15px;
|
||||
background: white;
|
||||
}
|
||||
.calendar-nav {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
.calendar-nav button {
|
||||
background: #4299e1;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 5px 12px;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.calendar-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(7, 1fr);
|
||||
gap: 4px;
|
||||
}
|
||||
.cal-weekday {
|
||||
text-align: center;
|
||||
font-size: 0.8em;
|
||||
color: #718096;
|
||||
padding: 8px 0;
|
||||
}
|
||||
.cal-day {
|
||||
aspect-ratio: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 6px;
|
||||
font-size: 0.9em;
|
||||
cursor: pointer;
|
||||
}
|
||||
.cal-day:hover:not(.empty) {
|
||||
background: #e2e8f0;
|
||||
}
|
||||
.cal-day.has-memory {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
font-weight: bold;
|
||||
}
|
||||
.cal-day.selected {
|
||||
border: 2px solid #ed8936;
|
||||
}
|
||||
.calendar-legend {
|
||||
margin-top: 15px;
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
font-size: 0.85em;
|
||||
}
|
||||
.legend-dot {
|
||||
display: inline-block;
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 50%;
|
||||
margin-right: 5px;
|
||||
}
|
||||
.legend-dot.has-memory {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
}
|
||||
.legend-dot.no-memory {
|
||||
background: #e2e8f0;
|
||||
}
|
||||
.memory-error {
|
||||
padding: 20px;
|
||||
color: #f56565;
|
||||
}
|
||||
@media (max-width: 768px) {
|
||||
.memory-body {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
.memory-calendar {
|
||||
order: -1;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
`;
|
||||
|
||||
currentMemoryModal = container;
|
||||
}
|
||||
|
||||
function renderCalendarDays(year, month, dates, selectedDate, lobsterId) {
|
||||
const firstDay = new Date(year, month, 1);
|
||||
const lastDay = new Date(year, month + 1, 0);
|
||||
const daysInMonth = lastDay.getDate();
|
||||
const startWeekday = firstDay.getDay();
|
||||
|
||||
let html = '';
|
||||
|
||||
// 空白
|
||||
for (let i = 0; i < startWeekday; i++) {
|
||||
html += '<div class="cal-day empty"></div>';
|
||||
}
|
||||
|
||||
// 日期
|
||||
for (let day = 1; day <= daysInMonth; day++) {
|
||||
const dateStr = `${year}-${String(month + 1).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
|
||||
const hasMemory = dates.includes(dateStr);
|
||||
const isSelected = selectedDate === dateStr;
|
||||
|
||||
html += `<div class="cal-day ${hasMemory ? 'has-memory' : ''} ${isSelected ? 'selected' : ''}"
|
||||
onclick="selectDate('${dateStr}', ${lobsterId})">${day}</div>`;
|
||||
}
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
function selectDate(date, lobsterId) {
|
||||
// 重新加载选中日期的日记
|
||||
const lobster = lobsters.find(l => l.id === lobsterId);
|
||||
if (lobster && currentMemoryModal) {
|
||||
currentMemoryModal.innerHTML = '';
|
||||
loadMemoryComponent(lobster, currentMemoryModal);
|
||||
}
|
||||
}
|
||||
|
||||
function changeMonth(delta) {
|
||||
// 简化:刷新页面重新计算月份
|
||||
location.reload();
|
||||
}
|
||||
|
||||
function closeMemory() {
|
||||
if (currentMemoryModal) {
|
||||
currentMemoryModal.remove();
|
||||
currentMemoryModal = null;
|
||||
}
|
||||
}
|
||||
|
||||
function escapeHtml(text) {
|
||||
if (!text) return '';
|
||||
return text
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"');
|
||||
}
|
||||
|
||||
// 渲染龙虾卡片
|
||||
function renderLobsterCard(lobster) {
|
||||
const status = 'healthy';
|
||||
const statusClass = status === 'healthy' ? 'status-healthy' : 'status-error';
|
||||
const statusText = status === 'healthy' ? '健康' : '异常';
|
||||
|
||||
return `
|
||||
<div class="lobster-card">
|
||||
<div class="lobster-header">
|
||||
<div class="lobster-name">
|
||||
${lobster.emoji} ${lobster.name}
|
||||
</div>
|
||||
<span class="status-indicator ${statusClass}" title="${statusText}"></span>
|
||||
</div>
|
||||
<div class="lobster-info">
|
||||
<div class="info-row">
|
||||
<span class="info-label">专长</span>
|
||||
<span class="info-value">${lobster.specialty}</span>
|
||||
</div>
|
||||
<div class="info-row">
|
||||
<span class="info-label">端口</span>
|
||||
<span class="info-value">${lobster.port}</span>
|
||||
</div>
|
||||
<div class="info-row">
|
||||
<span class="info-label">状态</span>
|
||||
<span class="info-value" style="color: ${status === 'healthy' ? '#48bb78' : '#f56565'}">${statusText}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="lobster-actions">
|
||||
<button class="action-btn btn-memory" onclick="openMemory(lobsters.find(l => l.id === ${lobster.id}))">🧠 记忆</button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
// 更新监控数据
|
||||
function updateDashboard() {
|
||||
const grid = document.getElementById('lobsterGrid');
|
||||
let healthy = 0, error = 0;
|
||||
|
||||
const results = lobsters.map(l => {
|
||||
healthy++;
|
||||
return { lobster: l, status: 'healthy' };
|
||||
});
|
||||
|
||||
grid.innerHTML = results.map(({ lobster }) =>
|
||||
renderLobsterCard(lobster)
|
||||
).join('');
|
||||
|
||||
document.getElementById('totalLobsters').textContent = lobsters.length;
|
||||
document.getElementById('healthyCount').textContent = healthy;
|
||||
document.getElementById('errorCount').textContent = error;
|
||||
document.getElementById('lastUpdate').textContent = new Date().toLocaleTimeString('zh-CN');
|
||||
}
|
||||
|
||||
// 初始化
|
||||
updateDashboard();
|
||||
setInterval(updateDashboard, 5000); // 每 5 秒刷新
|
||||
</script>
|
||||
<div id="root"></div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
17
code/frontend/src/App.js
Normal file
17
code/frontend/src/App.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import React from 'react';
|
||||
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
|
||||
import Dashboard from './pages/Dashboard';
|
||||
import LobsterDetail from './components/LobsterDetail';
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<Router>
|
||||
<Routes>
|
||||
<Route path="/" element={<Dashboard />} />
|
||||
<Route path="/lobster/:lobsterId" element={<LobsterDetail />} />
|
||||
</Routes>
|
||||
</Router>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
401
code/frontend/src/components/LobsterDetail/index.js
Normal file
401
code/frontend/src/components/LobsterDetail/index.js
Normal file
@@ -0,0 +1,401 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { useParams, useNavigate } from 'react-router-dom';
|
||||
import axios from 'axios';
|
||||
|
||||
const API_BASE = 'http://localhost:8000/api';
|
||||
|
||||
function LobsterDetail() {
|
||||
const { lobsterId } = useParams();
|
||||
const navigate = useNavigate();
|
||||
const [lobster, setLobster] = useState(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
fetchLobsterDetail();
|
||||
}, [lobsterId]);
|
||||
|
||||
const fetchLobsterDetail = async () => {
|
||||
try {
|
||||
const response = await axios.get(`${API_BASE}/lobsters/${lobsterId}/`);
|
||||
setLobster(response.data);
|
||||
setLoading(false);
|
||||
} catch (error) {
|
||||
console.error('获取龙虾详情失败:', error);
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const getStatusColor = (status) => {
|
||||
const colors = {
|
||||
healthy: '#48bb78',
|
||||
warning: '#ed8936',
|
||||
error: '#f56565',
|
||||
};
|
||||
return colors[status] || '#718096';
|
||||
};
|
||||
|
||||
const getStatusText = (status) => {
|
||||
const texts = {
|
||||
healthy: '运行正常',
|
||||
warning: '警告',
|
||||
error: '异常',
|
||||
};
|
||||
return texts[status] || status;
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="detail-loading">
|
||||
<div className="spinner"></div>
|
||||
<p>正在加载龙虾信息...</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!lobster) {
|
||||
return (
|
||||
<div className="detail-error">
|
||||
<h2>😕 未找到龙虾</h2>
|
||||
<p>这只龙虾可能不存在或已被移除</p>
|
||||
<button onClick={() => navigate('/')} className="back-btn">
|
||||
← 返回监控中心
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="lobster-detail">
|
||||
<div className="detail-header">
|
||||
<button onClick={() => navigate('/')} className="back-btn">
|
||||
← 返回监控中心
|
||||
</button>
|
||||
<h1>{lobster.emoji} {lobster.name} - 详细信息</h1>
|
||||
</div>
|
||||
|
||||
<div className="detail-content">
|
||||
{/* 基本信息卡片 */}
|
||||
<div className="info-card">
|
||||
<div className="card-header">
|
||||
<h2>📋 基本信息</h2>
|
||||
<span className={`status-badge status-${lobster.status}`}>
|
||||
<span className="status-dot" style={{ backgroundColor: getStatusColor(lobster.status) }}></span>
|
||||
{getStatusText(lobster.status)}
|
||||
</span>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
<div className="info-row">
|
||||
<span className="info-label">名称</span>
|
||||
<span className="info-value">{lobster.emoji} {lobster.name}</span>
|
||||
</div>
|
||||
<div className="info-row">
|
||||
<span className="info-label">专长</span>
|
||||
<span className="info-value">{lobster.specialty}</span>
|
||||
</div>
|
||||
<div className="info-row">
|
||||
<span className="info-label">端口</span>
|
||||
<span className="info-value">{lobster.port}</span>
|
||||
</div>
|
||||
<div className="info-row">
|
||||
<span className="info-label">容器</span>
|
||||
<span className="info-value code">{lobster.container}</span>
|
||||
</div>
|
||||
{lobster.workspace && (
|
||||
<div className="info-row">
|
||||
<span className="info-label">工作区</span>
|
||||
<span className="info-value code">{lobster.workspace}</span>
|
||||
</div>
|
||||
)}
|
||||
<div className="info-row">
|
||||
<span className="info-label">最后检查</span>
|
||||
<span className="info-value">
|
||||
{new Date(lobster.last_check).toLocaleString('zh-CN')}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 快速操作卡片 */}
|
||||
<div className="info-card">
|
||||
<div className="card-header">
|
||||
<h2>⚡ 快速操作</h2>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
<div className="action-buttons">
|
||||
<button
|
||||
className="action-btn primary"
|
||||
onClick={() => navigate(`/lobster/${lobsterId}/memory`)}
|
||||
>
|
||||
🧠 查看记忆
|
||||
</button>
|
||||
<button
|
||||
className="action-btn"
|
||||
onClick={() => window.open(`http://localhost:${lobster.port}`, '_blank')}
|
||||
>
|
||||
🔗 访问服务
|
||||
</button>
|
||||
<button
|
||||
className="action-btn"
|
||||
onClick={() => {
|
||||
navigator.clipboard.writeText(`http://localhost:${lobster.port}`);
|
||||
alert('已复制访问地址到剪贴板');
|
||||
}}
|
||||
>
|
||||
📋 复制地址
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 状态历史卡片 */}
|
||||
<div className="info-card">
|
||||
<div className="card-header">
|
||||
<h2>📊 运行统计</h2>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
<div className="stats-grid">
|
||||
<div className="stat-item">
|
||||
<div className="stat-value">99.9%</div>
|
||||
<div className="stat-label">可用性</div>
|
||||
</div>
|
||||
<div className="stat-item">
|
||||
<div className="stat-value">24/7</div>
|
||||
<div className="stat-label">运行时间</div>
|
||||
</div>
|
||||
<div className="stat-item">
|
||||
<div className="stat-value">0</div>
|
||||
<div className="stat-label">今日错误</div>
|
||||
</div>
|
||||
<div className="stat-item">
|
||||
<div className="stat-value">{lobster.port}</div>
|
||||
<div className="stat-label">服务端口</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>{`
|
||||
.lobster-detail {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.detail-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 20px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.detail-header h1 {
|
||||
color: #1a365d;
|
||||
margin: 0;
|
||||
font-size: 1.8em;
|
||||
}
|
||||
|
||||
.back-btn {
|
||||
background: #edf2f7;
|
||||
border: none;
|
||||
padding: 10px 20px;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
font-size: 1em;
|
||||
color: #4a5568;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.back-btn:hover {
|
||||
background: #e2e8f0;
|
||||
color: #2d3748;
|
||||
}
|
||||
|
||||
.detail-content {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.info-card {
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 20px;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.card-header h2 {
|
||||
margin: 0;
|
||||
font-size: 1.3em;
|
||||
}
|
||||
|
||||
.card-body {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.info-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 12px 0;
|
||||
border-bottom: 1px solid #e2e8f0;
|
||||
}
|
||||
|
||||
.info-row:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.info-label {
|
||||
color: #718096;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
color: #2d3748;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.info-value.code {
|
||||
font-family: 'Courier New', monospace;
|
||||
font-size: 0.9em;
|
||||
background: #f7fafc;
|
||||
padding: 4px 8px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.status-badge {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
padding: 6px 12px;
|
||||
border-radius: 20px;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.status-dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
animation: pulse 2s infinite;
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0%, 100% { opacity: 1; }
|
||||
50% { opacity: 0.5; }
|
||||
}
|
||||
|
||||
.action-buttons {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
background: #edf2f7;
|
||||
border: none;
|
||||
padding: 12px 20px;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
font-size: 1em;
|
||||
color: #4a5568;
|
||||
transition: all 0.2s;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.action-btn:hover {
|
||||
background: #e2e8f0;
|
||||
transform: translateX(5px);
|
||||
}
|
||||
|
||||
.action-btn.primary {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.action-btn.primary:hover {
|
||||
opacity: 0.9;
|
||||
transform: translateX(5px);
|
||||
}
|
||||
|
||||
.stats-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.stat-item {
|
||||
text-align: center;
|
||||
padding: 15px;
|
||||
background: #f7fafc;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-size: 1.8em;
|
||||
font-weight: bold;
|
||||
color: #667eea;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
color: #718096;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.detail-loading, .detail-error {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 400px;
|
||||
color: #718096;
|
||||
}
|
||||
|
||||
.detail-error h2 {
|
||||
color: #e53e3e;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border: 4px solid #e2e8f0;
|
||||
border-top-color: #667eea;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.detail-content {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.detail-header {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.stats-grid {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default LobsterDetail;
|
||||
10
code/frontend/src/index.js
Normal file
10
code/frontend/src/index.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import App from './App';
|
||||
|
||||
const root = ReactDOM.createRoot(document.getElementById('root'));
|
||||
root.render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>
|
||||
);
|
||||
@@ -1,4 +1,5 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import axios from 'axios';
|
||||
|
||||
const API_BASE = 'http://localhost:8000/api';
|
||||
@@ -6,6 +7,7 @@ const API_BASE = 'http://localhost:8000/api';
|
||||
function Dashboard() {
|
||||
const [lobsters, setLobsters] = useState([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
fetchLobsters();
|
||||
@@ -43,10 +45,10 @@ function Dashboard() {
|
||||
<p>容器:{lobster.container}</p>
|
||||
</div>
|
||||
<div className="lobster-actions">
|
||||
<button onClick={() => window.location.href = `/lobster/${lobster.id}`}>
|
||||
<button className="detail-btn" onClick={() => navigate(`/lobster/${lobster.id}`)}>
|
||||
📊 详情
|
||||
</button>
|
||||
<button onClick={() => window.location.href = `/lobster/${lobster.id}/memory`}>
|
||||
<button className="memory-btn" onClick={() => navigate(`/lobster/${lobster.id}/memory`)}>
|
||||
🧠 记忆
|
||||
</button>
|
||||
</div>
|
||||
@@ -58,3 +60,136 @@ function Dashboard() {
|
||||
}
|
||||
|
||||
export default Dashboard;
|
||||
|
||||
// CSS 样式
|
||||
const styles = `
|
||||
.dashboard {
|
||||
max-width: 1400px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.dashboard h1 {
|
||||
color: #1a365d;
|
||||
margin-bottom: 30px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.lobster-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.lobster-card {
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
padding: 20px;
|
||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
||||
transition: transform 0.2s;
|
||||
}
|
||||
|
||||
.lobster-card:hover {
|
||||
transform: translateY(-4px);
|
||||
box-shadow: 0 8px 12px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.lobster-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 15px;
|
||||
padding-bottom: 10px;
|
||||
border-bottom: 2px solid #e2e8f0;
|
||||
}
|
||||
|
||||
.lobster-name {
|
||||
font-size: 1.3em;
|
||||
font-weight: bold;
|
||||
color: #2d3748;
|
||||
}
|
||||
|
||||
.status {
|
||||
padding: 4px 12px;
|
||||
border-radius: 20px;
|
||||
font-size: 0.85em;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.status-healthy {
|
||||
background: #c6f6d5;
|
||||
color: #22543d;
|
||||
}
|
||||
|
||||
.status-warning {
|
||||
background: #feebc8;
|
||||
color: #744210;
|
||||
}
|
||||
|
||||
.status-error {
|
||||
background: #fed7d7;
|
||||
color: #742a2a;
|
||||
}
|
||||
|
||||
.lobster-info {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.lobster-info p {
|
||||
margin: 8px 0;
|
||||
color: #4a5568;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.lobster-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.lobster-actions button {
|
||||
flex: 1;
|
||||
padding: 10px 16px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 1em;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.detail-btn {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.detail-btn:hover {
|
||||
opacity: 0.9;
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 8px rgba(102, 126, 234, 0.4);
|
||||
}
|
||||
|
||||
.memory-btn {
|
||||
background: #edf2f7;
|
||||
color: #4a5568;
|
||||
}
|
||||
|
||||
.memory-btn:hover {
|
||||
background: #e2e8f0;
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.loading {
|
||||
text-align: center;
|
||||
padding: 50px;
|
||||
color: #718096;
|
||||
font-size: 1.2em;
|
||||
}
|
||||
`;
|
||||
|
||||
// 注入样式
|
||||
if (typeof document !== 'undefined') {
|
||||
const styleSheet = document.createElement('style');
|
||||
styleSheet.textContent = styles;
|
||||
document.head.appendChild(styleSheet);
|
||||
}
|
||||
|
||||
2
code/frontend/txt
Normal file
2
code/frontend/txt
Normal file
@@ -0,0 +1,2 @@
|
||||
# 找到进程并杀死
|
||||
lsof -ti :3000 | xargs kill -9
|
||||
Reference in New Issue
Block a user