feat: 新增 edc-web Flask 前端管理系统 + 需求文档
- edc-web: Flask 项目骨架(设备管理、测试操作、测试信息三大页面) - edc_server: 升级子模块(tb_serialnet 透传支持) - docs: 测试工装EDC管理系统需求文档
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
// 设备列表页
|
||||
|
||||
async function loadDevices() {
|
||||
const resp = await fetch("/api/devices");
|
||||
const devices = await resp.json();
|
||||
renderTable(devices);
|
||||
}
|
||||
|
||||
function renderTable(devices) {
|
||||
const tbody = document.querySelector("#device-table tbody");
|
||||
tbody.innerHTML = devices.map(d => `
|
||||
<tr>
|
||||
<td>${d.serial}</td>
|
||||
<td class="editable-name" onclick="editName(${d.id}, '${esc(d.name)}', this)">
|
||||
${d.name || '(点击编辑)'}
|
||||
</td>
|
||||
<td>${d.ip || '-'}</td>
|
||||
<td class="${d.state === 1 ? 'status-online' : 'status-offline'}">
|
||||
${d.state === 1 ? '在线' : '离线'}
|
||||
</td>
|
||||
<td>${d.version || '-'}</td>
|
||||
<td>${d.last_login || '-'}</td>
|
||||
<td>
|
||||
<button class="btn-test" onclick="location.href='/test/${d.id}'">测试</button>
|
||||
</td>
|
||||
</tr>
|
||||
`).join("");
|
||||
}
|
||||
|
||||
function esc(s) { return s.replace(/'/g, "\\'").replace(/"/g, """); }
|
||||
|
||||
async function editName(id, currentName, td) {
|
||||
const input = document.createElement("input");
|
||||
input.value = currentName;
|
||||
td.innerHTML = "";
|
||||
td.appendChild(input);
|
||||
input.focus();
|
||||
|
||||
async function save() {
|
||||
const name = input.value.trim();
|
||||
td.textContent = name || "(点击编辑)";
|
||||
await fetch(`/api/devices/${id}/name`, {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ name }),
|
||||
});
|
||||
}
|
||||
|
||||
input.addEventListener("blur", save);
|
||||
input.addEventListener("keydown", e => { if (e.key === "Enter") save(); });
|
||||
}
|
||||
|
||||
loadDevices();
|
||||
Reference in New Issue
Block a user