diff --git a/js/admin.js b/js/admin.js index 0946946..97b7fcc 100644 --- a/js/admin.js +++ b/js/admin.js @@ -210,6 +210,10 @@ function renderAdminLinks() { }); } +// ============================================================ +// ⚙️ 论坛设置(含自定义 CSS) +// ============================================================ + function renderAdminSettings() { const container = document.getElementById('adminContent'); container.innerHTML = ` @@ -374,6 +378,166 @@ function renderAdminSettings() { }); } +// ============================================================ +// 📄 自定义页面管理 +// ============================================================ + +let editingPageId = null; + +function renderAdminCustomPages() { + const container = document.getElementById('adminContent'); + container.innerHTML = ` +
+

📄 自定义页面

+ +
+
+ `; + + loadCustomPageList(); + + document.getElementById('addCustomPageBtn').addEventListener('click', function() { + editingPageId = null; + openCustomPageEditor(); + }); +} + +function loadCustomPageList() { + const container = document.getElementById('customPageList'); + container.innerHTML = '
加载中...
'; + API.getAdminCustomPages().then(pages => { + if (pages.length === 0) { + container.innerHTML = '
暂无自定义页面
'; + return; + } + let html = `
+ + + + + + + + + + + + `; + pages.forEach(p => { + html += ` + + + + + + + + `; + }); + html += '
名称标题URL状态操作
${p.name}${p.title}?custom=${p.name}${p.enabled ? '✅ 启用' : '❌ 禁用'} + + +
'; + container.innerHTML = html; + + container.querySelectorAll('[data-action="edit"]').forEach(btn => { + btn.addEventListener('click', function() { + const page = pages.find(p => p.id === this.dataset.id); + if (page) { + editingPageId = page.id; + openCustomPageEditor(page); + } + }); + }); + + container.querySelectorAll('[data-action="delete"]').forEach(btn => { + btn.addEventListener('click', function() { + if (!confirm('确定要删除这个页面吗?')) return; + API.deleteCustomPage(this.dataset.id).then(() => { + loadCustomPageList(); + loadCustomPagesNav(); + }).catch(err => alert('删除失败:' + err.message)); + }); + }); + }).catch(err => { + container.innerHTML = '
加载失败
'; + }); +} + +function openCustomPageEditor(page) { + const isEdit = !!page; + 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('#editorSaveBtn').addEventListener('click', async function() { + const name = document.getElementById('editorPageName').value.trim(); + const title = document.getElementById('editorPageTitle').value.trim(); + const content = document.getElementById('editorContent').value.trim(); + const enabled = document.getElementById('editorEnabled').value === 'true'; + + if (!name) { alert('请输入页面名称'); return; } + if (!title) { alert('请输入导航栏显示名称'); return; } + if (!content) { alert('请输入页面内容'); return; } + if (!/^[a-zA-Z0-9\-_]+$/.test(name)) { + alert('页面名称只允许字母、数字、短横线和下划线'); + return; + } + + try { + if (isEdit) { + await API.updateCustomPage(page.id, title, content, enabled); + } else { + await API.createCustomPage(name, title, content); + } + modal.remove(); + loadCustomPageList(); + loadCustomPagesNav(); + } catch (err) { + alert('保存失败:' + err.message); + } + }); +} + // ============================================================ // 自定义 CSS 警告模态框 // ============================================================