fix: save calibration with config action
This commit is contained in:
@@ -57,9 +57,9 @@ app.innerHTML = `
|
||||
RTSP 地址
|
||||
<input id="rtspUrl" type="text" placeholder="rtsp://user:password@camera-ip:554/stream">
|
||||
</label>
|
||||
<button id="saveConfig" type="button">保存配置</button>
|
||||
<button id="saveConfig" type="button">保存配置和标定</button>
|
||||
<button id="captureSnapshot" type="button">抓取一帧</button>
|
||||
<button id="saveCalibration" type="button">保存标定到配置</button>
|
||||
<button id="saveCalibration" type="button">仅保存标定</button>
|
||||
</section>
|
||||
|
||||
<section class="calibration-grid">
|
||||
@@ -184,9 +184,10 @@ async function saveConfig() {
|
||||
},
|
||||
};
|
||||
state.config = await apiJson("/api/manage/config", {method: "PUT", body: payload});
|
||||
const calibrationSaved = await persistCalibration({requireAny: false});
|
||||
fillForm();
|
||||
renderConfigPreview();
|
||||
setStatus("配置已保存");
|
||||
setStatus(calibrationSaved ? "配置和标定已保存" : "配置已保存;当前没有可保存的标定点");
|
||||
} catch (error) {
|
||||
setStatus(`保存配置失败:${error.message}`);
|
||||
}
|
||||
@@ -225,29 +226,38 @@ async function captureSnapshot() {
|
||||
|
||||
async function saveCalibration() {
|
||||
try {
|
||||
const zones = zoneIds
|
||||
.map((id) => ({id, polygon: state.polygons[id]}))
|
||||
.filter((zone) => zone.polygon.length >= 3);
|
||||
const trashPolygon = state.polygons.trash;
|
||||
if (zones.length !== zoneIds.length) {
|
||||
setStatus("8 个格口都标定后才能保存");
|
||||
return;
|
||||
const saved = await persistCalibration({requireAny: true});
|
||||
if (saved) {
|
||||
render();
|
||||
setStatus("标定已保存到项目配置");
|
||||
}
|
||||
if (trashPolygon.length < 3) {
|
||||
setStatus("垃圾桶区域至少需要 3 个点");
|
||||
return;
|
||||
}
|
||||
state.config = await apiJson("/api/manage/calibration", {
|
||||
method: "PUT",
|
||||
body: {zones, trash: {roi: trashPolygon}},
|
||||
});
|
||||
render();
|
||||
setStatus("标定已保存到项目配置");
|
||||
} catch (error) {
|
||||
setStatus(`保存标定失败:${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function persistCalibration({requireAny}) {
|
||||
const zones = zoneIds
|
||||
.map((id) => ({id, polygon: state.polygons[id]}))
|
||||
.filter((zone) => zone.polygon.length >= 3);
|
||||
const trashPolygon = state.polygons.trash;
|
||||
const payload = {zones, trash: {}};
|
||||
if (trashPolygon.length >= 3) {
|
||||
payload.trash.roi = trashPolygon;
|
||||
}
|
||||
if (!zones.length && !payload.trash.roi) {
|
||||
if (requireAny) {
|
||||
setStatus("当前没有可保存的标定点;每个区域至少需要 3 个点");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
state.config = await apiJson("/api/manage/calibration", {
|
||||
method: "PUT",
|
||||
body: payload,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
function setTab(tab) {
|
||||
state.activeTab = tab;
|
||||
document.querySelectorAll(".tabs button").forEach((button) => {
|
||||
|
||||
Reference in New Issue
Block a user