2024-12-15 06:07:02 +00:00
|
|
|
R"(<!DOCTYPE html>
|
|
|
|
<html><head>
|
2024-12-15 08:14:52 +00:00
|
|
|
<meta charset="UTF-8">
|
2024-12-18 09:39:21 +00:00
|
|
|
<title>PETInfusion 监控</title>
|
2024-12-15 06:07:02 +00:00
|
|
|
<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;
|
|
|
|
}
|
2024-12-26 16:08:45 +00:00
|
|
|
h3 {
|
|
|
|
margin: 0 0 10px 0;
|
|
|
|
color: #333;
|
|
|
|
font-size: 1.1em;
|
|
|
|
text-align: center;
|
|
|
|
}
|
2024-12-15 06:07:02 +00:00
|
|
|
form {
|
2024-12-26 16:08:45 +00:00
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
2024-12-15 06:07:02 +00:00
|
|
|
background: white;
|
|
|
|
border-radius: 8px;
|
|
|
|
}
|
|
|
|
.form-group {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2024-12-26 16:08:45 +00:00
|
|
|
margin-bottom: 15px;
|
2024-12-15 06:07:02 +00:00
|
|
|
}
|
2024-12-26 16:08:45 +00:00
|
|
|
.form-group label {
|
|
|
|
width: 120px;
|
|
|
|
text-align: right;
|
|
|
|
padding-right: 10px;
|
|
|
|
flex-shrink: 0;
|
2024-12-15 06:07:02 +00:00
|
|
|
}
|
2024-12-26 16:08:45 +00:00
|
|
|
.form-group input {
|
|
|
|
width: calc(100% - 130px);
|
|
|
|
height: 28px;
|
|
|
|
padding: 0 8px;
|
2024-12-15 06:07:02 +00:00
|
|
|
border: 1px solid #ddd;
|
|
|
|
border-radius: 4px;
|
2024-12-26 16:08:45 +00:00
|
|
|
}
|
|
|
|
.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;
|
2024-12-15 06:07:02 +00:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
2024-12-15 08:14:52 +00:00
|
|
|
|
|
|
|
.device-status,.network-config {
|
|
|
|
background: white;
|
|
|
|
padding: 20px;
|
|
|
|
border-radius: 8px;
|
|
|
|
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
2024-12-26 16:08:45 +00:00
|
|
|
width: 70%;
|
2024-12-15 08:14:52 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-12-26 16:08:45 +00:00
|
|
|
|
2024-12-15 08:14:52 +00:00
|
|
|
|
|
|
|
.status-value {
|
|
|
|
display: flex;
|
|
|
|
justify-content: space-between;
|
|
|
|
align-items: center;
|
|
|
|
margin: 5px 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.status-label {
|
|
|
|
font-weight: bold;
|
|
|
|
color: #555;
|
|
|
|
}
|
|
|
|
|
|
|
|
.error {
|
2024-12-18 14:32:01 +00:00
|
|
|
font-weight: bold;
|
2024-12-15 08:14:52 +00:00
|
|
|
color: #dc3545;
|
2024-12-18 14:32:01 +00:00
|
|
|
background-color: yellow;
|
|
|
|
transition: color 0.3s ease;
|
2024-12-15 08:14:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.success {
|
|
|
|
color: #28a745;
|
2024-12-18 14:32:01 +00:00
|
|
|
transition: color 0.3s ease;
|
2024-12-15 08:14:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.warning {
|
|
|
|
color: #ffc107;
|
2024-12-18 14:32:01 +00:00
|
|
|
transition: color 0.3s ease;
|
2024-12-15 08:14:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-26 16:08:45 +00:00
|
|
|
.device-params {
|
|
|
|
gap: 20px;
|
2024-12-15 08:14:52 +00:00
|
|
|
}
|
2024-12-26 16:08:45 +00:00
|
|
|
|
|
|
|
.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%;
|
|
|
|
}
|
|
|
|
|
2024-12-15 06:07:02 +00:00
|
|
|
</style>
|
|
|
|
<script>
|
2024-12-26 16:08:45 +00:00
|
|
|
// 参数配置模板
|
|
|
|
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';
|
2024-12-15 06:07:02 +00:00
|
|
|
|
2024-12-26 16:08:45 +00:00
|
|
|
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')
|
2024-12-17 08:25:23 +00:00
|
|
|
.then(response => response.json())
|
|
|
|
.then(data => {
|
2024-12-26 16:08:45 +00:00
|
|
|
// 填充泵参数
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2024-12-17 08:25:23 +00:00
|
|
|
})
|
|
|
|
.catch(error => {
|
2024-12-26 16:08:45 +00:00
|
|
|
console.error('加载设备参数失败:', error);
|
2024-12-17 08:25:23 +00:00
|
|
|
});
|
2024-12-15 06:07:02 +00:00
|
|
|
});
|
2024-12-26 16:08:45 +00:00
|
|
|
|
|
|
|
// 如果需要动态添加新的泵或阀,可以调用:
|
|
|
|
// generateDeviceGroup('pump', 新的数量);
|
2024-12-15 06:07:02 +00:00
|
|
|
</script>
|
|
|
|
</head><body>
|
2024-12-15 08:14:52 +00:00
|
|
|
<div class='device-status'>
|
2024-12-18 09:39:21 +00:00
|
|
|
<h2>系统状态信息</h2>
|
2024-12-15 08:14:52 +00:00
|
|
|
|
|
|
|
<div class='status-group'>
|
|
|
|
<!-- 设备信息行 -->
|
|
|
|
<div class='status-row'>
|
|
|
|
<div class='status-item full-width'>
|
2024-12-26 16:08:45 +00:00
|
|
|
<h3>设备状态</h3>
|
2024-12-15 08:14:52 +00:00
|
|
|
<div class='status-value'>
|
2024-12-26 16:08:45 +00:00
|
|
|
<span class='status-label'>下挂设备状态</span>
|
2024-12-15 08:14:52 +00:00
|
|
|
<span id='device-status'>#</span>
|
|
|
|
</div>
|
|
|
|
<div class='status-value'>
|
2024-12-18 09:39:21 +00:00
|
|
|
<span class='status-label'>初始化状态</span>
|
2024-12-15 08:14:52 +00:00
|
|
|
<span id='init-status'>#</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- 设备运行状态行 -->
|
|
|
|
<div class='status-row device-running'>
|
|
|
|
<div class='status-item'>
|
2024-12-18 09:39:21 +00:00
|
|
|
<h3>三通阀状态</h3>
|
2024-12-15 08:14:52 +00:00
|
|
|
<div class='status-value'>
|
2024-12-18 09:39:21 +00:00
|
|
|
<span class='status-label'>1#阀角度</span>
|
2024-12-15 08:14:52 +00:00
|
|
|
<span id='valve1-angle'>#</span>
|
|
|
|
</div>
|
|
|
|
<div class='status-value'>
|
2024-12-18 09:39:21 +00:00
|
|
|
<span class='status-label'>2#阀角度</span>
|
2024-12-15 08:14:52 +00:00
|
|
|
<span id='valve2-angle'>#</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class='status-item'>
|
2024-12-18 09:39:21 +00:00
|
|
|
<h3>泵状态</h3>
|
2024-12-15 08:14:52 +00:00
|
|
|
<div class='status-value'>
|
2024-12-18 09:39:21 +00:00
|
|
|
<span class='status-label'>1#泵</span>
|
2024-12-15 08:14:52 +00:00
|
|
|
<span id='pump1-status'>#</span>
|
|
|
|
</div>
|
|
|
|
<div class='status-value'>
|
2024-12-18 09:39:21 +00:00
|
|
|
<span class='status-label'>2#泵</span>
|
2024-12-15 08:14:52 +00:00
|
|
|
<span id='pump2-status'>#</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class='status-item'>
|
2024-12-18 09:39:21 +00:00
|
|
|
<h3>传感器状态</h3>
|
2024-12-15 08:14:52 +00:00
|
|
|
<div class='status-value'>
|
2024-12-18 09:39:21 +00:00
|
|
|
<span class='status-label'>气泡传感器</span>
|
2024-12-15 08:14:52 +00:00
|
|
|
<span id='bubble-status'>#</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2024-12-26 16:08:45 +00:00
|
|
|
<div class='status-item'>
|
2024-12-18 09:39:21 +00:00
|
|
|
<h3>急停</h3>
|
2024-12-15 08:14:52 +00:00
|
|
|
<div class='status-value'>
|
2024-12-18 09:39:21 +00:00
|
|
|
<span class='status-label'>状态</span>
|
2024-12-15 08:14:52 +00:00
|
|
|
<span id='stop-status'>#</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- 错误状态行 -->
|
|
|
|
<div class='status-row'>
|
|
|
|
<div class='status-item full-width'>
|
2024-12-18 09:39:21 +00:00
|
|
|
<h3>错误状态</h3>
|
2024-12-15 08:14:52 +00:00
|
|
|
<div class='status-value'>
|
2024-12-18 09:39:21 +00:00
|
|
|
<span class='status-label'>错误信息</span>
|
2024-12-15 08:14:52 +00:00
|
|
|
<span id='error-status'>#</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
2024-12-26 16:08:45 +00:00
|
|
|
<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>
|
|
|
|
|
2024-12-15 08:14:52 +00:00
|
|
|
<div class='network-config'>
|
|
|
|
<h2>参数设置</h2>
|
2024-12-15 06:07:02 +00:00
|
|
|
<form method='post' action='/config'>
|
|
|
|
<div class='form-group'>
|
2024-12-18 09:39:21 +00:00
|
|
|
<label>MAC地址:</label>
|
2024-12-17 08:25:23 +00:00
|
|
|
<input type='text' name='mac' value='#:#:#:#:#:#'>
|
2024-12-15 06:07:02 +00:00
|
|
|
</div>
|
|
|
|
<div class='form-group'>
|
2024-12-18 09:39:21 +00:00
|
|
|
<label>IP地址:</label>
|
2024-12-17 08:25:23 +00:00
|
|
|
<input type='text' name='ip' value='#.#.#.#'>
|
2024-12-15 06:07:02 +00:00
|
|
|
</div>
|
|
|
|
<div class='form-group'>
|
2024-12-18 09:39:21 +00:00
|
|
|
<label>子网地址:</label>
|
2024-12-17 08:25:23 +00:00
|
|
|
<input type='text' name='subnet' value='#.#.#.#'>
|
2024-12-15 06:07:02 +00:00
|
|
|
</div>
|
|
|
|
<div class='form-group'>
|
2024-12-18 09:39:21 +00:00
|
|
|
<label>网关地址:</label>
|
2024-12-17 08:25:23 +00:00
|
|
|
<input type='text' name='gateway' value='#.#.#.#'>
|
2024-12-15 06:07:02 +00:00
|
|
|
</div>
|
2024-12-18 09:39:21 +00:00
|
|
|
<input type='submit' value='保存配置'>
|
2024-12-15 06:07:02 +00:00
|
|
|
</form>
|
|
|
|
</div>
|
2024-12-15 08:14:52 +00:00
|
|
|
|
2024-12-15 06:07:02 +00:00
|
|
|
</body></html>)"
|