分离html并优化
This commit is contained in:
264
data/index.html
Normal file
264
data/index.html
Normal file
@ -0,0 +1,264 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>ESP32 实时监控面板</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: 'Segoe UI', sans-serif;
|
||||
background-color: #f5f7fa;
|
||||
color: #333;
|
||||
padding: 30px;
|
||||
max-width: 1000px;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
h1 {
|
||||
text-align: center;
|
||||
color: #1890ff;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 20px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.data-box {
|
||||
flex: 1;
|
||||
min-width: 140px;
|
||||
background-color: white;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 6px rgba(0,0,0,0.05);
|
||||
padding: 12px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.data-label {
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.data-value {
|
||||
font-size: 20px;
|
||||
font-weight: bold;
|
||||
color: #1890ff;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.control-section {
|
||||
margin-top: 30px;
|
||||
background-color: white;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 2px 6px rgba(0,0,0,0.05);
|
||||
}
|
||||
|
||||
.control-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.control-group label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
color: #555;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.control-group input[type="range"] {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.control-group input[type="number"] {
|
||||
width: 100px;
|
||||
padding: 6px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.wiper-value {
|
||||
display: inline-block;
|
||||
font-size: 16px;
|
||||
color: #1890ff;
|
||||
font-weight: bold;
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
||||
button {
|
||||
padding: 8px 16px;
|
||||
margin: 5px 5px 0 0;
|
||||
background-color: #1890ff;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.3s;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background-color: #40a9ff;
|
||||
}
|
||||
|
||||
.status-inline {
|
||||
font-weight: bold;
|
||||
color: #1890ff;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
async function fetchData() {
|
||||
const res = await fetch('/data');
|
||||
if (!res.ok) return alert('获取数据失败');
|
||||
const data = await res.json();
|
||||
|
||||
document.getElementById('duration').innerText = data.duration;
|
||||
document.getElementById('temperature').innerText = data.temperature + ' °C';
|
||||
document.getElementById('humidity').innerText = data.humidity + ' %RH';
|
||||
document.getElementById('lightA').innerText = data.lightA + ' lx';
|
||||
document.getElementById('lightB').innerText = data.lightB + ' lx';
|
||||
document.getElementById('busVoltage').innerText = data.busVoltage + ' V';
|
||||
document.getElementById('current').innerText = data.current + ' A';
|
||||
document.getElementById('power').innerText = data.power + ' W';
|
||||
document.getElementById('wiperNow').innerText = data.wiper;
|
||||
|
||||
const lightStatus = await (await fetch('/lightStatus')).text();
|
||||
document.getElementById('lightStatus').innerText = lightStatus === 'on' ? '开启' : '关闭';
|
||||
|
||||
const autoStatus = await (await fetch('/autoAdjustStatus')).text();
|
||||
document.getElementById('autoAdjustStatus').innerText = autoStatus === 'enabled' ? '开启' : '关闭';
|
||||
}
|
||||
|
||||
function updateWiperDisplay() {
|
||||
const val = document.getElementById('wiperValue').value;
|
||||
document.getElementById('wiperDisplay').innerText = val;
|
||||
}
|
||||
|
||||
async function setWiper() {
|
||||
const val = document.getElementById('wiperValue').value;
|
||||
const res = await fetch('/setWiper', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
body: 'value=' + encodeURIComponent(val)
|
||||
});
|
||||
alert(res.ok ? 'Wiper 设置成功!' : '设置失败');
|
||||
}
|
||||
|
||||
async function resetDuration() {
|
||||
const res = await fetch('/resetDuration', { method: 'POST' });
|
||||
alert(res.ok ? '已清空累计时长' : '操作失败');
|
||||
}
|
||||
|
||||
async function turnOnLight() {
|
||||
const res = await fetch('/LightOpen', { method: 'POST' });
|
||||
if (res.ok) document.getElementById('lightStatus').innerText = '开启';
|
||||
else alert('打开失败');
|
||||
}
|
||||
|
||||
async function turnOffLight() {
|
||||
const res = await fetch('/LightClose', { method: 'POST' });
|
||||
if (res.ok) document.getElementById('lightStatus').innerText = '关闭';
|
||||
else alert('关闭失败');
|
||||
}
|
||||
|
||||
async function enableAutoAdjust() {
|
||||
const val = document.getElementById('targetLux').value;
|
||||
if (!val || val <= 0 || val > 65535) {
|
||||
alert('请输入合理的照度(1~65535)');
|
||||
return;
|
||||
}
|
||||
const res = await fetch('/startAutoAdjust', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
body: 'target=' + encodeURIComponent(val)
|
||||
});
|
||||
alert(res.ok ? '已开启自动调节' : '开启失败');
|
||||
}
|
||||
|
||||
async function disableAutoAdjust() {
|
||||
const res = await fetch('/stopAutoAdjust', { method: 'POST' });
|
||||
alert(res.ok ? '已关闭自动调节' : '关闭失败');
|
||||
}
|
||||
|
||||
setInterval(fetchData, 1000);
|
||||
</script>
|
||||
</head>
|
||||
<body onload="fetchData()">
|
||||
|
||||
<h1>📟 ESP32 实时监控面板</h1>
|
||||
|
||||
<div class="row">
|
||||
<div class="data-box">
|
||||
<div class="data-label">累计使用时长</div>
|
||||
<div class="data-value" id="duration">--</div>
|
||||
</div>
|
||||
<div class="data-box">
|
||||
<button onclick="resetDuration()">清空累计时长</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 温湿度 -->
|
||||
<div class="row">
|
||||
<div class="data-box">
|
||||
<div class="data-label">温度</div>
|
||||
<div class="data-value" id="temperature">--</div>
|
||||
</div>
|
||||
<div class="data-box">
|
||||
<div class="data-label">湿度</div>
|
||||
<div class="data-value" id="humidity">--</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 光照 -->
|
||||
<div class="row">
|
||||
<div class="data-box">
|
||||
<div class="data-label">光照 A</div>
|
||||
<div class="data-value" id="lightA">--</div>
|
||||
</div>
|
||||
<div class="data-box">
|
||||
<div class="data-label">光照 B</div>
|
||||
<div class="data-value" id="lightB">--</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 电源信息(已去除分流电压) -->
|
||||
<div class="row">
|
||||
<div class="data-box">
|
||||
<div class="data-label">总线电压</div>
|
||||
<div class="data-value" id="busVoltage">--</div>
|
||||
</div>
|
||||
<div class="data-box">
|
||||
<div class="data-label">电流</div>
|
||||
<div class="data-value" id="current">--</div>
|
||||
</div>
|
||||
<div class="data-box">
|
||||
<div class="data-label">功率</div>
|
||||
<div class="data-value" id="power">--</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 控制面板 -->
|
||||
<div class="control-section">
|
||||
<div class="control-group">
|
||||
<label>Wiper 当前值:<span class="status-inline" id="wiperNow">--</span></label>
|
||||
<input type="range" id="wiperValue" min="0" max="100" value="0" oninput="updateWiperDisplay()" />
|
||||
<span class="wiper-value" id="wiperDisplay">0</span>
|
||||
<button onclick="setWiper()">设置</button>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label>灯光状态:<span class="status-inline" id="lightStatus">--</span></label>
|
||||
<button onclick="turnOnLight()">开灯</button>
|
||||
<button onclick="turnOffLight()">关灯</button>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label>自动调节状态:<span class="status-inline" id="autoAdjustStatus">--</span></label>
|
||||
<input type="number" id="targetLux" min="1" max="65535" value="2000" />
|
||||
<button onclick="enableAutoAdjust()">开启</button>
|
||||
<button onclick="disableAutoAdjust()">关闭</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user