Compare commits

...

3 Commits

Author SHA1 Message Date
436f897711 fix: 修复编辑弹框关闭确认只提示一次的问题
- 定义命名函数作为监听器
- 每次打开编辑弹框时移除旧监听器再添加新监听器
- 确保每次关闭时都能检查是否有修改
2026-04-19 23:09:15 +08:00
9d6cea0453 feat: 编辑弹框关闭时检查是否有修改并提示确认
- 打开编辑弹框时保存原始数据状态
- 关闭时比较当前内容和原始内容
- 如果有修改,弹出确认对话框询问是否放弃修改
- 保存成功后清除原始数据标记
2026-04-19 18:49:35 +08:00
c9433a5e98 fix: 修复编辑草稿时重复创建新草稿的问题
- showAddModal 不再重置 currentDraftId
- 编辑已有草稿时会更新该草稿而不是创建新草稿
2026-04-19 18:08:00 +08:00

View File

@@ -1860,8 +1860,8 @@ function showAddModal(type) {
// 设置类型
document.getElementById('addType').value = type;
// 重置草稿ID
currentDraftId = null;
// 只有不是编辑草稿时才重置
// currentDraftId 在 editDraft 中已设置,不要覆盖
// 设置弹窗标题和图标
const typeInfo = {
@@ -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}`);
@@ -2185,7 +2194,66 @@ async function openEditModal(id) {
// 设置重点关注状态
document.getElementById('editStarred').checked = item.is_starred === 1;
new bootstrap.Modal(document.getElementById('editModal')).show();
// 保存原始数据用于比较
window.editOriginalData = {
type,
title: item.title || '',
content: item.content || '',
url: item.url || '',
source: item.source || '',
status: item.status,
priority: item.priority,
due_date: item.due_date,
note: item.note || '',
tags: item.tags.join(', '),
is_starred: item.is_starred
};
// 移除旧的监听器,添加新的监听器
const editModal = document.getElementById('editModal');
editModal.removeEventListener('hide.bs.modal', editModalHideHandler);
editModal.addEventListener('hide.bs.modal', editModalHideHandler);
const modal = new bootstrap.Modal(editModal);
modal.show();
}
}
// 检查编辑内容是否有修改
function hasEditChanges() {
if (!window.editOriginalData) return false;
const type = document.getElementById('editType').value;
const current = {
type,
title: document.getElementById('editTitle').value,
content: document.getElementById('editContent').value,
url: document.getElementById('editUrl').value,
source: document.getElementById('editSource').value,
note: document.getElementById('editNote').value,
tags: document.getElementById('editTags').value,
is_starred: document.getElementById('editStarred').checked ? 1 : 0
};
if (type === 'todo') {
current.status = document.getElementById('editStatus').value;
current.priority = document.getElementById('editPriority').value;
current.due_date = document.getElementById('editDueDate').value;
}
// 比较各字段
return current.title !== window.editOriginalData.title ||
current.content !== (window.editOriginalData.content || '') ||
current.url !== (window.editOriginalData.url || '') ||
current.source !== (window.editOriginalData.source || '') ||
current.note !== (window.editOriginalData.note || '') ||
current.tags !== window.editOriginalData.tags ||
current.is_starred !== window.editOriginalData.is_starred ||
(type === 'todo' && (
current.status !== window.editOriginalData.status ||
current.priority !== window.editOriginalData.priority ||
current.due_date !== (window.editOriginalData.due_date || '')
));
}
// 根据类型更新编辑表单字段显示
@@ -2225,6 +2293,7 @@ async function saveEdit() {
const result = await res.json();
if (res.ok && result.success) {
window.editOriginalData = null; // 清除原始数据,避免关闭时询问
bootstrap.Modal.getInstance(document.getElementById('editModal')).hide();
refreshData();
} else {