fix: 修复编辑弹框关闭确认只提示一次的问题
- 定义命名函数作为监听器 - 每次打开编辑弹框时移除旧监听器再添加新监听器 - 确保每次关闭时都能检查是否有修改
This commit is contained in:
@@ -2139,6 +2139,15 @@ function openEditModalFromDetail() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 打开编辑模态框
|
// 打开编辑模态框
|
||||||
|
// 编辑弹框关闭确认监听器函数
|
||||||
|
function editModalHideHandler(e) {
|
||||||
|
if (hasEditChanges()) {
|
||||||
|
if (!confirm('您已修改内容但未保存,是否放弃修改?')) {
|
||||||
|
e.preventDefault(); // 取消关闭
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function openEditModal(id) {
|
async function openEditModal(id) {
|
||||||
currentDetailId = id;
|
currentDetailId = id;
|
||||||
const res = await fetch(`${API_BASE}/items/${id}`);
|
const res = await fetch(`${API_BASE}/items/${id}`);
|
||||||
@@ -2200,17 +2209,14 @@ async function openEditModal(id) {
|
|||||||
is_starred: item.is_starred
|
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);
|
||||||
|
|
||||||
// 监听关闭事件,检查是否有修改
|
const modal = new bootstrap.Modal(editModal);
|
||||||
document.getElementById('editModal').addEventListener('hide.bs.modal', function(e) {
|
modal.show();
|
||||||
if (hasEditChanges()) {
|
}
|
||||||
if (!confirm('您已修改内容但未保存,是否放弃修改?')) {
|
|
||||||
e.preventDefault(); // 取消关闭
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, { once: true });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查编辑内容是否有修改
|
// 检查编辑内容是否有修改
|
||||||
|
|||||||
Reference in New Issue
Block a user