Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 94efc524c6 | |||
| 436f897711 |
@@ -2139,6 +2139,15 @@ function openEditModalFromDetail() {
|
||||
}
|
||||
|
||||
// 打开编辑模态框
|
||||
// 编辑弹框关闭确认监听器函数
|
||||
function editModalHideHandler(e) {
|
||||
if (hasEditChanges()) {
|
||||
if (!confirm('您已修改内容但未保存,是否放弃修改?')) {
|
||||
e.preventDefault(); // 取消关闭
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function openEditModal(id) {
|
||||
currentDetailId = id;
|
||||
const res = await fetch(`${API_BASE}/items/${id}`);
|
||||
@@ -2200,17 +2209,13 @@ async function openEditModal(id) {
|
||||
is_starred: item.is_starred
|
||||
};
|
||||
|
||||
const modal = new bootstrap.Modal(document.getElementById('editModal'));
|
||||
modal.show();
|
||||
// 移除旧的监听器,添加新的监听器
|
||||
const editModal = document.getElementById('editModal');
|
||||
editModal.removeEventListener('hide.bs.modal', editModalHideHandler);
|
||||
editModal.addEventListener('hide.bs.modal', editModalHideHandler);
|
||||
|
||||
// 监听关闭事件,检查是否有修改
|
||||
document.getElementById('editModal').addEventListener('hide.bs.modal', function(e) {
|
||||
if (hasEditChanges()) {
|
||||
if (!confirm('您已修改内容但未保存,是否放弃修改?')) {
|
||||
e.preventDefault(); // 取消关闭
|
||||
}
|
||||
}
|
||||
}, { once: true });
|
||||
const modal = new bootstrap.Modal(editModal);
|
||||
modal.show();
|
||||
}
|
||||
|
||||
// 检查编辑内容是否有修改
|
||||
|
||||
Reference in New Issue
Block a user