Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 436f897711 | |||
| 9d6cea0453 | |||
| c9433a5e98 |
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user