153 lines
5.3 KiB
HTML
153 lines
5.3 KiB
HTML
|
<!DOCTYPE html>
|
||
|
<html lang="zh">
|
||
|
<head>
|
||
|
<meta charset="UTF-8">
|
||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
<title>SCPI命令参数编辑器</title>
|
||
|
<style>
|
||
|
body {
|
||
|
font-family: Arial, sans-serif;
|
||
|
margin: 0;
|
||
|
padding: 20px;
|
||
|
box-sizing: border-box;
|
||
|
}
|
||
|
.command-container {
|
||
|
display: flex;
|
||
|
flex-wrap: wrap;
|
||
|
justify-content: space-between;
|
||
|
gap: 10px;
|
||
|
}
|
||
|
.command-row {
|
||
|
box-sizing: border-box;
|
||
|
height: inherit;
|
||
|
/* margin: 10px 0; */
|
||
|
padding: 10px ;
|
||
|
border: 1px solid #ddd;
|
||
|
border-radius: 4px;
|
||
|
display: flex;
|
||
|
flex: 1 1 30%;
|
||
|
flex-direction: column;
|
||
|
/* width: calc(30% - 20px); */
|
||
|
|
||
|
}
|
||
|
.comment-input {
|
||
|
display: inline-block;
|
||
|
width: 100%;
|
||
|
height: 100%;
|
||
|
padding: 5px;
|
||
|
border: none;
|
||
|
background: none;
|
||
|
font-size: 14px;
|
||
|
cursor: text;
|
||
|
}
|
||
|
.command-label {
|
||
|
display: inline-block;
|
||
|
width: auto;
|
||
|
font-family: monospace;
|
||
|
margin-top: 5px;
|
||
|
}
|
||
|
.value-input {
|
||
|
width: auto;
|
||
|
padding: 5px;
|
||
|
margin-top: 5px;
|
||
|
}
|
||
|
.update-btn {
|
||
|
width: auto;
|
||
|
margin-top: 10px;
|
||
|
padding: 5px 10px;
|
||
|
background-color: #4CAF50;
|
||
|
color: white;
|
||
|
border: none;
|
||
|
border-radius: 4px;
|
||
|
cursor: pointer;
|
||
|
}
|
||
|
.update-btn:hover {
|
||
|
background-color: #45a049;
|
||
|
}
|
||
|
</style>
|
||
|
</head>
|
||
|
<body>
|
||
|
<h1>SCPI命令参数编辑器</h1>
|
||
|
<div class="command-container" id="commands-container"></div>
|
||
|
|
||
|
<script>
|
||
|
async function loadCommands() {
|
||
|
const response = await fetch('commands.json');
|
||
|
const commands = await response.json();
|
||
|
const commentsResponse = await fetch('comments.json');
|
||
|
const comments = await commentsResponse.json();
|
||
|
const container = document.getElementById('commands-container');
|
||
|
|
||
|
for (const [command, value] of Object.entries(commands)) {
|
||
|
const row = document.createElement('div');
|
||
|
row.className = 'command-row';
|
||
|
|
||
|
const commentDisplay = document.createElement('span');
|
||
|
commentDisplay.className = 'comment-input';
|
||
|
commentDisplay.textContent = comments[command] || '';
|
||
|
commentDisplay.ondblclick = () => {
|
||
|
const commentInput = document.createElement('input');
|
||
|
commentInput.type = 'text';
|
||
|
commentInput.value = commentDisplay.textContent;
|
||
|
commentInput.onblur = async () => {
|
||
|
comments[command] = commentInput.value;
|
||
|
commentDisplay.textContent = commentInput.value;
|
||
|
row.replaceChild(commentDisplay, commentInput);
|
||
|
await fetch('/save_comments', {
|
||
|
method: 'POST',
|
||
|
headers: {
|
||
|
'Content-Type': 'application/json',
|
||
|
},
|
||
|
body: JSON.stringify(comments)
|
||
|
});
|
||
|
};
|
||
|
row.replaceChild(commentInput, commentDisplay);
|
||
|
commentInput.focus();
|
||
|
};
|
||
|
|
||
|
const label = document.createElement('span');
|
||
|
label.className = 'command-label';
|
||
|
label.textContent = command;
|
||
|
|
||
|
const input = document.createElement('input');
|
||
|
input.className = 'value-input';
|
||
|
input.type = 'text';
|
||
|
input.value = value;
|
||
|
|
||
|
const button = document.createElement('button');
|
||
|
button.className = 'update-btn';
|
||
|
button.textContent = '更新';
|
||
|
button.onclick = async () => {
|
||
|
if (confirm(`确认要将命令 ${command} 的参数更新为 ${input.value} 吗?`)) {
|
||
|
const response = await fetch('/update_command', {
|
||
|
method: 'POST',
|
||
|
headers: {
|
||
|
'Content-Type': 'application/json',
|
||
|
},
|
||
|
body: JSON.stringify({
|
||
|
command: command,
|
||
|
value: input.value
|
||
|
})
|
||
|
});
|
||
|
|
||
|
if (response.ok) {
|
||
|
alert('更新成功!');
|
||
|
} else {
|
||
|
alert('更新失败!');
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
row.appendChild(commentDisplay);
|
||
|
// row.appendChild(document.createElement('br'));
|
||
|
row.appendChild(label);
|
||
|
row.appendChild(input);
|
||
|
row.appendChild(button);
|
||
|
container.appendChild(row);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
window.onload = loadCommands;
|
||
|
</script>
|
||
|
</body>
|
||
|
</html>
|