455 lines
11 KiB
HTML
455 lines
11 KiB
HTML
R"(<!DOCTYPE html>
|
|
<html><head>
|
|
<meta charset="UTF-8">
|
|
<title>PETInfusion 监控</title>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
margin: 20px auto;
|
|
padding: 20px;
|
|
background-color: #f5f5f5;
|
|
}
|
|
h2 {
|
|
color: #333;
|
|
text-align: center;
|
|
}
|
|
h3 {
|
|
margin: 0 0 10px 0;
|
|
color: #333;
|
|
font-size: 1.1em;
|
|
text-align: center;
|
|
}
|
|
form {
|
|
display: flex;
|
|
flex-direction: column;
|
|
background: white;
|
|
border-radius: 8px;
|
|
}
|
|
.form-group {
|
|
display: flex;
|
|
align-items: center;
|
|
margin-bottom: 15px;
|
|
}
|
|
.form-group label {
|
|
width: 120px;
|
|
text-align: right;
|
|
padding-right: 10px;
|
|
flex-shrink: 0;
|
|
}
|
|
.form-group input {
|
|
width: calc(100% - 130px);
|
|
height: 28px;
|
|
padding: 0 8px;
|
|
border: 1px solid #ddd;
|
|
border-radius: 4px;
|
|
}
|
|
.form-group input:focus {
|
|
border-color: #007bff;
|
|
outline: none;
|
|
box-shadow: 0 0 0 2px rgba(0,123,255,0.25);
|
|
}
|
|
.form-group input[type="number"] {
|
|
-moz-appearance: textfield;
|
|
}
|
|
.form-group input[type="number"]::-webkit-outer-spin-button,
|
|
.form-group input[type="number"]::-webkit-inner-spin-button {
|
|
-webkit-appearance: none;
|
|
margin: 0;
|
|
}
|
|
input[type='submit'] {
|
|
background-color: #4CAF50;
|
|
color: white;
|
|
padding: 10px 20px;
|
|
border: none;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
font-size: 16px;
|
|
margin-top: 10px;
|
|
width: 100%;
|
|
display: block;
|
|
margin: 20px auto 0;
|
|
}
|
|
input[type='submit']:hover {
|
|
background-color: #45a049;
|
|
}
|
|
.status {
|
|
margin-top: 20px;
|
|
padding: 10px;
|
|
border-radius: 4px;
|
|
text-align: center;
|
|
width: 100%;
|
|
margin: 20px auto;
|
|
box-sizing: border-box;
|
|
}
|
|
.connected {
|
|
background-color: #dff0d8;
|
|
color: #3c763d;
|
|
border: 1px solid #d6e9c6;
|
|
}
|
|
.disconnected {
|
|
background-color: #f2dede;
|
|
color: #a94442;
|
|
border: 1px solid #ebccd1;
|
|
}
|
|
|
|
.loading {
|
|
display: none;
|
|
text-align: center;
|
|
padding: 10px;
|
|
color: #666;
|
|
}
|
|
|
|
.loading.active {
|
|
display: block;
|
|
}
|
|
|
|
form.submitting input {
|
|
opacity: 0.7;
|
|
pointer-events: none;
|
|
}
|
|
|
|
input[type='submit'].loading {
|
|
background-color: #cccccc;
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
.device-status,.network-config {
|
|
background: white;
|
|
padding: 20px;
|
|
border-radius: 8px;
|
|
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
width: 70%;
|
|
margin: 20px auto;
|
|
}
|
|
|
|
.status-group {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 15px;
|
|
}
|
|
|
|
.status-row {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 15px;
|
|
}
|
|
|
|
.status-item {
|
|
flex: 1;
|
|
min-width: 200px;
|
|
padding: 15px;
|
|
border: 1px solid #ddd;
|
|
border-radius: 4px;
|
|
background-color: #fff;
|
|
}
|
|
|
|
|
|
|
|
.status-value {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin: 5px 0;
|
|
}
|
|
|
|
.status-label {
|
|
font-weight: bold;
|
|
color: #555;
|
|
}
|
|
|
|
.error {
|
|
font-weight: bold;
|
|
color: #dc3545;
|
|
background-color: yellow;
|
|
transition: color 0.3s ease;
|
|
}
|
|
|
|
.success {
|
|
color: #28a745;
|
|
transition: color 0.3s ease;
|
|
}
|
|
|
|
.warning {
|
|
color: #ffc107;
|
|
transition: color 0.3s ease;
|
|
}
|
|
|
|
.status-row.device-running {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 15px;
|
|
}
|
|
|
|
.status-row.device-running .status-item {
|
|
flex: 1;
|
|
min-width: 200px;
|
|
}
|
|
|
|
@media screen and (min-width: 900px) {
|
|
.status-row.device-running .status-item {
|
|
flex: 1;
|
|
min-width: 0;
|
|
width: calc(33.33% - 10px);
|
|
}
|
|
}
|
|
|
|
.device-params {
|
|
gap: 20px;
|
|
}
|
|
|
|
.device-group {
|
|
flex: 1;
|
|
min-width: 300px;
|
|
}
|
|
|
|
.device-row {
|
|
display: flex;
|
|
gap: 20px;
|
|
margin-bottom: 20px;
|
|
flex-wrap: wrap;
|
|
}
|
|
|
|
.motor-params {
|
|
flex: 1;
|
|
padding: 15px;
|
|
border-radius: 5px;
|
|
border: 1px solid #ddd;
|
|
}
|
|
|
|
.form-row {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 20px;
|
|
width: 100%;
|
|
}
|
|
|
|
</style>
|
|
<script>
|
|
// 参数配置模板
|
|
const motorParamFields = [
|
|
{ name: 'name', label: '名称', type: 'text', maxLength: 20 },
|
|
{ name: 'id', label: 'ID', type: 'number', min: 0, max: 255 },
|
|
{ name: 'speed', label: '满速(步/秒)', type: 'number' },
|
|
{ name: 'accel', label: '加速度', type: 'number' },
|
|
{ name: 'decel', label: '减速度', type: 'number' },
|
|
{ name: 'fullCount', label: '总步数', type: 'number' },
|
|
{ name: 'offsetPos', label: '偏移位置', type: 'number' },
|
|
{ name: 'speedPercent', label: '速度百分比(%)', type: 'number', min: 0, max: 100 },
|
|
{ name: 'torque', label: '堵转力矩(%)', type: 'number', min: 0, max: 100 },
|
|
{ name: 'timeout', label: '超时时间(秒)', type: 'number' }
|
|
];
|
|
|
|
// 生成单个设备的参数表单
|
|
function generateMotorParams(deviceType, index) {
|
|
const motorDiv = document.createElement('div');
|
|
motorDiv.className = 'motor-params';
|
|
|
|
const title = document.createElement('h3');
|
|
title.textContent = `${deviceType}${index + 1}参数`;
|
|
motorDiv.appendChild(title);
|
|
|
|
motorParamFields.forEach(field => {
|
|
const formGroup = document.createElement('div');
|
|
formGroup.className = 'form-group';
|
|
|
|
const label = document.createElement('label');
|
|
label.textContent = field.label + ':';
|
|
|
|
const input = document.createElement('input');
|
|
input.type = field.type;
|
|
input.name = `${deviceType}${index + 1}_${field.name}`;
|
|
|
|
// 设置输入限制
|
|
if (field.maxLength) input.maxLength = field.maxLength;
|
|
if (field.min !== undefined) input.min = field.min;
|
|
if (field.max !== undefined) input.max = field.max;
|
|
|
|
formGroup.appendChild(label);
|
|
formGroup.appendChild(input);
|
|
motorDiv.appendChild(formGroup);
|
|
});
|
|
|
|
return motorDiv;
|
|
}
|
|
|
|
// 生成设备组的参数表单
|
|
function generateDeviceGroup(deviceType, count) {
|
|
const container = document.getElementById(`${deviceType}-container`);
|
|
container.innerHTML = ''; // 清空现有内容
|
|
|
|
for (let i = 0; i < count; i++) {
|
|
const motorParams = generateMotorParams(deviceType, i);
|
|
container.appendChild(motorParams);
|
|
}
|
|
}
|
|
|
|
// 页面加载时初始化表单
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
// 初始化泵和阀的参数表单
|
|
generateDeviceGroup('pump', 2); // 生成2个泵的参数
|
|
generateDeviceGroup('valve', 2); // 生成2个阀的参数
|
|
|
|
// 获取设备参数并填充表单
|
|
fetch('/device-params')
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
// 填充泵参数
|
|
data.pump.forEach((pump, index) => {
|
|
Object.keys(pump).forEach(key => {
|
|
const input = document.querySelector(`input[name="pump${index + 1}_${key}"]`);
|
|
if (input) {
|
|
if (key === 'name') {
|
|
input.value = new TextDecoder().decode(new Uint8Array(pump[key]));
|
|
} else {
|
|
input.value = pump[key];
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
// 填充阀参数
|
|
data.valve.forEach((valve, index) => {
|
|
Object.keys(valve).forEach(key => {
|
|
const input = document.querySelector(`input[name="valve${index + 1}_${key}"]`);
|
|
if (input) {
|
|
if (key === 'name') {
|
|
input.value = new TextDecoder().decode(new Uint8Array(valve[key]));
|
|
} else {
|
|
input.value = valve[key];
|
|
}
|
|
}
|
|
});
|
|
});
|
|
})
|
|
.catch(error => {
|
|
console.error('加载设备参数失败:', error);
|
|
});
|
|
});
|
|
|
|
// 如果需要动态添加新的泵或阀,可以调用:
|
|
// generateDeviceGroup('pump', 新的数量);
|
|
</script>
|
|
</head><body>
|
|
<div class='device-status'>
|
|
<h2>系统状态信息</h2>
|
|
|
|
<div class='status-group'>
|
|
<!-- 设备信息行 -->
|
|
<div class='status-row'>
|
|
<div class='status-item full-width'>
|
|
<h3>设备状态</h3>
|
|
<div class='status-value'>
|
|
<span class='status-label'>下挂设备状态</span>
|
|
<span id='device-status'>#</span>
|
|
</div>
|
|
<div class='status-value'>
|
|
<span class='status-label'>初始化状态</span>
|
|
<span id='init-status'>#</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 设备运行状态行 -->
|
|
<div class='status-row device-running'>
|
|
<div class='status-item'>
|
|
<h3>三通阀状态</h3>
|
|
<div class='status-value'>
|
|
<span class='status-label'>1#阀角度</span>
|
|
<span id='valve1-angle'>#</span>
|
|
</div>
|
|
<div class='status-value'>
|
|
<span class='status-label'>2#阀角度</span>
|
|
<span id='valve2-angle'>#</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class='status-item'>
|
|
<h3>泵状态</h3>
|
|
<div class='status-value'>
|
|
<span class='status-label'>1#泵</span>
|
|
<span id='pump1-status'>#</span>
|
|
</div>
|
|
<div class='status-value'>
|
|
<span class='status-label'>2#泵</span>
|
|
<span id='pump2-status'>#</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class='status-item'>
|
|
<h3>传感器状态</h3>
|
|
<div class='status-value'>
|
|
<span class='status-label'>气泡传感器</span>
|
|
<span id='bubble-status'>#</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class='status-item'>
|
|
<h3>急停</h3>
|
|
<div class='status-value'>
|
|
<span class='status-label'>状态</span>
|
|
<span id='stop-status'>#</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 错误状态行 -->
|
|
<div class='status-row'>
|
|
<div class='status-item full-width'>
|
|
<h3>错误状态</h3>
|
|
<div class='status-value'>
|
|
<span class='status-label'>错误信息</span>
|
|
<span id='error-status'>#</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<div class='network-config'>
|
|
<h2>设备参数设置</h2>
|
|
<form method='post' action='/device-params'>
|
|
<div class='device-params'>
|
|
<div class='device-group' id='pump-group'>
|
|
<h3>泵参数设置</h3>
|
|
<div class='device-row' id='pump-container'>
|
|
<!-- 泵参数将由JS动态生成 -->
|
|
</div>
|
|
</div>
|
|
|
|
<div class='device-group' id='valve-group'>
|
|
<h3>阀参数设置</h3>
|
|
<div class='device-row' id='valve-container'>
|
|
<!-- 阀参数将由JS动态生成 -->
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<input type='submit' value='保存设备参数'>
|
|
</form>
|
|
</div>
|
|
|
|
<div class='network-config'>
|
|
<h2>参数设置</h2>
|
|
<form method='post' action='/config'>
|
|
<div class='form-group'>
|
|
<label>MAC地址:</label>
|
|
<input type='text' name='mac' value='#:#:#:#:#:#'>
|
|
</div>
|
|
<div class='form-group'>
|
|
<label>IP地址:</label>
|
|
<input type='text' name='ip' value='#.#.#.#'>
|
|
</div>
|
|
<div class='form-group'>
|
|
<label>子网地址:</label>
|
|
<input type='text' name='subnet' value='#.#.#.#'>
|
|
</div>
|
|
<div class='form-group'>
|
|
<label>网关地址:</label>
|
|
<input type='text' name='gateway' value='#.#.#.#'>
|
|
</div>
|
|
<input type='submit' value='保存配置'>
|
|
</form>
|
|
</div>
|
|
|
|
</body></html>)" |