diff --git a/js/app.js b/js/app.js index ad745f8..072dfa8 100644 --- a/js/app.js +++ b/js/app.js @@ -650,6 +650,54 @@ async function renderSettingsPage() { } } +// ============================================================ +// ✏️ 编辑帖子模态框 +// ============================================================ + +function openEditModal(postId, currentTitle, currentContent) { + const modal = document.createElement('div'); + modal.className = 'modal active'; + modal.style.display = 'flex'; + modal.innerHTML = ` +
+ `; + + document.body.appendChild(modal); + + modal.querySelector('.close').addEventListener('click', function() { + modal.remove(); + }); + modal.addEventListener('click', function(e) { + if (e.target === this) modal.remove(); + }); + + modal.querySelector('#editPostSaveBtn').addEventListener('click', async function() { + const title = document.getElementById('editPostTitle').value.trim() || '无标题'; + const content = document.getElementById('editPostContent').value.trim(); + if (!content) { alert('请填写内容'); return; } + + try { + await API.updatePost(postId, title, content); + modal.remove(); + // 刷新当前视图 + if (currentPage === 'post') { + renderPostDetail(currentPostId); + } else { + renderFeed(); + } + alert('编辑成功!'); + } catch (err) { + alert('编辑失败:' + err.message); + } + }); +} + // ============================================================ // 🚀 初始化 // ============================================================