336 lines
9.9 KiB
HTML
336 lines
9.9 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<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: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
|
background: #f5f7fa;
|
|
min-height: 100vh;
|
|
}
|
|
|
|
.header {
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
color: white;
|
|
padding: 20px;
|
|
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
}
|
|
|
|
.header h1 {
|
|
font-size: 24px;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
}
|
|
|
|
.user-info {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 15px;
|
|
}
|
|
|
|
.logout-btn {
|
|
background: rgba(255, 255, 255, 0.2);
|
|
border: 1px solid rgba(255, 255, 255, 0.3);
|
|
color: white;
|
|
padding: 8px 15px;
|
|
border-radius: 5px;
|
|
cursor: pointer;
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.logout-btn:hover {
|
|
background: rgba(255, 255, 255, 0.3);
|
|
}
|
|
|
|
.container {
|
|
max-width: 1200px;
|
|
margin: 30px auto;
|
|
padding: 0 20px;
|
|
}
|
|
|
|
.dashboard-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
|
gap: 20px;
|
|
margin-bottom: 30px;
|
|
}
|
|
|
|
.card {
|
|
background: white;
|
|
border-radius: 15px;
|
|
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
|
|
padding: 25px;
|
|
transition: transform 0.3s ease, box-shadow 0.3s ease;
|
|
}
|
|
|
|
.card:hover {
|
|
transform: translateY(-5px);
|
|
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.12);
|
|
}
|
|
|
|
.card h3 {
|
|
color: #333;
|
|
margin-bottom: 15px;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
}
|
|
|
|
.card p {
|
|
color: #666;
|
|
line-height: 1.6;
|
|
}
|
|
|
|
.device-control {
|
|
background: white;
|
|
border-radius: 15px;
|
|
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
|
|
padding: 25px;
|
|
margin-bottom: 30px;
|
|
}
|
|
|
|
.device-control h2 {
|
|
color: #333;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.form-group {
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
label {
|
|
display: block;
|
|
margin-bottom: 8px;
|
|
color: #555;
|
|
font-weight: 500;
|
|
}
|
|
|
|
select, input {
|
|
width: 100%;
|
|
padding: 12px;
|
|
border: 2px solid #e1e1e1;
|
|
border-radius: 8px;
|
|
font-size: 16px;
|
|
outline: none;
|
|
}
|
|
|
|
select:focus, input:focus {
|
|
border-color: #667eea;
|
|
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
|
|
}
|
|
|
|
button {
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
color: white;
|
|
border: none;
|
|
padding: 12px 25px;
|
|
border-radius: 8px;
|
|
font-size: 16px;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
button:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
|
|
}
|
|
|
|
.status-indicator {
|
|
display: inline-block;
|
|
width: 12px;
|
|
height: 12px;
|
|
border-radius: 50%;
|
|
margin-right: 8px;
|
|
}
|
|
|
|
.status-online {
|
|
background-color: #27ae60;
|
|
}
|
|
|
|
.status-offline {
|
|
background-color: #e74c3c;
|
|
}
|
|
|
|
.notification {
|
|
padding: 15px;
|
|
border-radius: 8px;
|
|
margin: 15px 0;
|
|
display: none;
|
|
}
|
|
|
|
.notification.success {
|
|
background-color: #d4edda;
|
|
color: #155724;
|
|
border: 1px solid #c3e6cb;
|
|
}
|
|
|
|
.notification.error {
|
|
background-color: #f8d7da;
|
|
color: #721c24;
|
|
border: 1px solid #f5c6cb;
|
|
}
|
|
|
|
@media (max-width: 768px) {
|
|
.dashboard-grid {
|
|
grid-template-columns: 1fr;
|
|
}
|
|
|
|
.header {
|
|
flex-direction: column;
|
|
gap: 15px;
|
|
text-align: center;
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="header">
|
|
<h1>🐷 猪场管理系统</h1>
|
|
<div class="user-info">
|
|
<span id="username">用户</span>
|
|
<button class="logout-btn" id="logoutBtn">退出登录</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="container">
|
|
<div class="dashboard-grid">
|
|
<div class="card">
|
|
<h3>📊 系统状态</h3>
|
|
<p>当前系统运行正常</p>
|
|
<p>连接设备: <span id="deviceCount">0</span> 台</p>
|
|
<p>今日操作: <span id="operationCount">0</span> 次</p>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<h3>🌡️ 环境监控</h3>
|
|
<p>温度: <span id="temperature">25.6</span>°C</p>
|
|
<p>湿度: <span id="humidity">65</span>%</p>
|
|
<p>空气质量: 良好</p>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<h3>📡 设备连接</h3>
|
|
<p>中继设备: <span class="status-indicator status-online"></span>在线</p>
|
|
<p>风扇设备: <span class="status-indicator status-online"></span>在线</p>
|
|
<p>水帘设备: <span class="status-indicator status-offline"></span>离线</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="device-control">
|
|
<h2>⚙️ 设备控制</h2>
|
|
<div class="notification" id="controlNotification"></div>
|
|
|
|
<div class="form-group">
|
|
<label for="deviceType">设备类型</label>
|
|
<select id="deviceType">
|
|
<option value="fan">风扇</option>
|
|
<option value="water_curtain">水帘</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="deviceId">设备ID</label>
|
|
<input type="text" id="deviceId" placeholder="请输入设备ID">
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="action">操作</label>
|
|
<select id="action">
|
|
<option value="on">开启</option>
|
|
<option value="off">关闭</option>
|
|
</select>
|
|
</div>
|
|
|
|
<button id="controlBtn">执行控制</button>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
// 检查用户是否已登录
|
|
const token = localStorage.getItem('authToken');
|
|
const username = localStorage.getItem('username');
|
|
|
|
if (!token) {
|
|
window.location.href = '/index.html';
|
|
} else {
|
|
document.getElementById('username').textContent = username;
|
|
}
|
|
|
|
// 退出登录
|
|
document.getElementById('logoutBtn').addEventListener('click', function() {
|
|
localStorage.removeItem('authToken');
|
|
localStorage.removeItem('userId');
|
|
localStorage.removeItem('username');
|
|
window.location.href = '/index.html';
|
|
});
|
|
|
|
// 设备控制
|
|
document.getElementById('controlBtn').addEventListener('click', async function() {
|
|
const deviceType = document.getElementById('deviceType').value;
|
|
const deviceId = document.getElementById('deviceId').value;
|
|
const action = document.getElementById('action').value;
|
|
const notification = document.getElementById('controlNotification');
|
|
|
|
if (!deviceId) {
|
|
showNotification('请输入设备ID', 'error');
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const response = await fetch('/api/v1/device/switch', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Authorization': `Bearer ${token}`
|
|
},
|
|
body: JSON.stringify({
|
|
device_type: deviceType,
|
|
device_id: deviceId,
|
|
action: action
|
|
})
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (response.ok && data.code === 0) {
|
|
showNotification(`设备控制成功: ${data.message}`, 'success');
|
|
} else {
|
|
showNotification(`控制失败: ${data.message || '未知错误'}`, 'error');
|
|
}
|
|
} catch (error) {
|
|
showNotification('网络错误,请稍后重试', 'error');
|
|
}
|
|
});
|
|
|
|
// 显示通知
|
|
function showNotification(message, type) {
|
|
const notification = document.getElementById('controlNotification');
|
|
notification.textContent = message;
|
|
notification.className = 'notification ' + type;
|
|
notification.style.display = 'block';
|
|
|
|
// 3秒后自动隐藏
|
|
setTimeout(() => {
|
|
notification.style.display = 'none';
|
|
}, 3000);
|
|
}
|
|
|
|
// 模拟获取设备数量
|
|
document.getElementById('deviceCount').textContent = '12';
|
|
document.getElementById('operationCount').textContent = '24';
|
|
</script>
|
|
</body>
|
|
</html> |