feat: 添加龙虾详情页面功能
- 新建 LobsterDetail 组件,显示龙虾详细信息
- 添加 React Router 路由配置 (/lobster/:id)
- Dashboard 添加详情按钮,支持跳转到详情页
- 详情页功能:
* 基本信息展示(名称、专长、端口、容器、工作区)
* 运行状态指示器(带脉冲动画)
* 快速操作(查看记忆、访问服务、复制地址)
* 运行统计卡片
- 修复 index.html 缺少 root 挂载点问题
- 添加一键重启脚本 restart.sh
- 更新任务跟踪文档
🦸 北极星指引方向,飞行侠展翅飞翔
This commit is contained in:
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user