fix: 弹窗innerHTML覆盖导致事件丢失,改用DOM构建

This commit is contained in:
tian 2026-07-24 15:18:48 +08:00
parent 64febdc0cb
commit 6034af086c
2 changed files with 16 additions and 8 deletions

View File

@ -248,7 +248,8 @@
box.style.cssText = 'background:var(--surface);border-radius:8px;padding:20px;min-width:300px;max-width:400px';
box.addEventListener('click',function(e){e.stopPropagation()});
box.innerHTML = '<div style="font-size:14px;font-weight:600;margin-bottom:12px">为设备添加视频源 (' + visible.length + '路可用)</div>' +
'<div style="max-height:60vh;overflow-y:auto;margin-bottom:12px">';
'<div style="max-height:60vh;overflow-y:auto;margin-bottom:0"></div>';
var list = box.querySelector('div:last-child');
visible.forEach(function(name) {
var item = document.createElement('div');
item.textContent = name;
@ -259,10 +260,13 @@
addSourceToDeviceForm(deviceID, name);
overlay.remove();
});
box.querySelector('div:last-child').appendChild(item);
list.appendChild(item);
});
box.innerHTML += '</div><div style="text-align:right"><button class="btn" style="font-size:12px">取消</button></div>';
box.querySelector('button').addEventListener('click',function(){overlay.remove()});
var footer = document.createElement('div');
footer.style.cssText = 'margin-top:12px;text-align:right';
footer.innerHTML = '<button class="btn" style="font-size:12px">取消</button>';
footer.querySelector('button').addEventListener('click',function(){overlay.remove()});
box.appendChild(footer);
overlay.appendChild(box);
document.body.appendChild(overlay);
};
@ -306,7 +310,8 @@
box.style.cssText = 'background:var(--surface);border-radius:8px;padding:20px;min-width:300px;max-width:400px';
box.addEventListener('click',function(e){e.stopPropagation()});
box.innerHTML = '<div style="font-size:14px;font-weight:600;margin-bottom:12px">分配 "' + sourceName + '" 到设备</div>' +
'<div style="max-height:60vh;overflow-y:auto;margin-bottom:12px">';
'<div style="max-height:60vh;overflow-y:auto;margin-bottom:0"></div>';
var list = box.querySelector('div:last-child');
rows.forEach(function(row) {
var did = row.getAttribute('data-device-id');
var nameEl = row.querySelector('.console-device-name');
@ -322,10 +327,13 @@
addSourceToDeviceForm(did, sourceName);
overlay.remove();
});
box.querySelector('div:last-child').appendChild(item);
list.appendChild(item);
});
box.innerHTML += '</div><div style="text-align:right"><button class="btn" style="font-size:12px">取消</button></div>';
box.querySelector('button').addEventListener('click',function(){overlay.remove()});
var footer = document.createElement('div');
footer.style.cssText = 'margin-top:12px;text-align:right';
footer.innerHTML = '<button class="btn" style="font-size:12px">取消</button>';
footer.querySelector('button').addEventListener('click',function(){overlay.remove()});
box.appendChild(footer);
overlay.appendChild(box);
document.body.appendChild(overlay);
}

Binary file not shown.