feat: port upstream custom pages, notifications, recovery codes, account security

- schema: custom_pages, notifications, recovery_codes tables + UNIQUE(conversations) + posts.edited_at
- API: custom-pages CRUD (public + admin), notifications (list/read/read-all), recovery-codes (generate/count/reset-password), user avatar/password/email, post edit
- UI: custom page nav links + iframe rendering, admin custom pages tab with editor modal, messages page shows notifications, settings page gains avatar upload, password/email change, recovery codes manager
- Sync globals.css with upstream rewrite
This commit is contained in:
lezi-fun committed 2026-08-10 09:07:06 +08:00
1 parent 9e72e4de8e
commit 4732e7d61d
28 files changed
+1196 -255

No files matched your search

+86
View File
@@ -0,0 +1,86 @@
'use client';
// 管理后台 - 自定义页面管理(列表)
import { useEffect, useState } from 'react';
import { API } from '@/lib/api';
import CustomPageEditor from './CustomPageEditor';
export default function AdminCustomPages() {
const [pages, setPages] = useState(null);
const [error, setError] = useState(null);
const [editing, setEditing] = useState(null); // null | 'new' | page对象
const load = () => {
API.adminGetCustomPages()
.then((data) => { setPages(data || []); setError(null); })
.catch((e) => { setError(e.message); setPages([]); });
};
useEffect(load, []);
const handleDelete = async (p) => {
if (!confirm('确定要删除这个页面吗?')) return;
try {
await API.adminDeleteCustomPage(p.id);
load();
} catch (err) {
alert('删除失败:' + err.message);
}
};
if (error) return <div style={{ textAlign: 'center', color: '#ef4444', padding: 20 }}>加载失败:{error}</div>;
return (
<>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16 }}>
<h3 style={{ margin: 0 }}>📄 自定义页面</h3>
<button className="btn-primary" style={{ padding: '8px 16px' }} onClick={() => setEditing('new')}>➕ 添加页面</button>
</div>
<div id="customPageList">
{pages === null ? (
<div style={{ textAlign: 'center', color: '#94a3b8', padding: 20 }}>加载中...</div>
) : pages.length === 0 ? (
<div style={{ textAlign: 'center', color: '#94a3b8', padding: 20 }}>暂无自定义页面</div>
) : (
<div style={{ overflowX: 'auto' }}>
<table style={{ width: '100%', borderCollapse: 'collapse', fontSize: 14 }}>
<thead>
<tr style={{ textAlign: 'left', borderBottom: '2px solid var(--border)' }}>
<th style={{ padding: '8px 12px' }}>名称</th>
<th style={{ padding: '8px 12px' }}>标题</th>
<th style={{ padding: '8px 12px' }}>URL</th>
<th style={{ padding: '8px 12px' }}>状态</th>
<th style={{ padding: '8px 12px', textAlign: 'center' }}>操作</th>
</tr>
</thead>
<tbody>
{pages.map((p) => (
<tr key={p.id} style={{ borderBottom: '1px solid var(--border-light)' }}>
<td style={{ padding: '8px 12px' }}><code style={{ background: 'var(--bg)', padding: '2px 6px', borderRadius: 4, fontSize: 12 }}>{p.name}</code></td>
<td style={{ padding: '8px 12px' }}>{p.title}</td>
<td style={{ padding: '8px 12px' }}><code style={{ background: 'var(--bg)', padding: '2px 6px', borderRadius: 4, fontSize: 12 }}>?custom={p.name}</code></td>
<td style={{ padding: '8px 12px' }}>
<span style={{ color: p.enabled ? '#22c55e' : '#ef4444' }}>{p.enabled ? '✅ 启用' : '❌ 禁用'}</span>
</td>
<td style={{ padding: '8px 12px', textAlign: 'center', display: 'flex', gap: 6, justifyContent: 'center' }}>
<button className="btn-sm btn-secondary" onClick={() => setEditing(p)}>✏️</button>
<button className="btn-sm btn-danger" onClick={() => handleDelete(p)}>🗑️</button>
</td>
</tr>
))}
</tbody>
</table>
</div>
)}
</div>
{editing && (
<CustomPageEditor
page={editing === 'new' ? null : editing}
onClose={() => setEditing(null)}
onSaved={() => { setEditing(null); load(); }}
/>
)}
</>
);
}
+88
View File
@@ -0,0 +1,88 @@
'use client';
// 管理后台 - 自定义页面编辑器(modal)
import { useState } from 'react';
import { API } from '@/lib/api';
export default function CustomPageEditor({ page, onClose, onSaved }) {
const isEdit = !!page;
const [name, setName] = useState(page?.name || '');
const [title, setTitle] = useState(page?.title || '');
const [content, setContent] = useState(page?.content || '');
const [enabled, setEnabled] = useState(page?.enabled !== false);
const handleSave = async () => {
if (!name.trim()) { alert('请输入页面名称'); return; }
if (!title.trim()) { alert('请输入导航栏显示名称'); return; }
if (!content.trim()) { alert('请输入页面内容'); return; }
if (!/^[a-zA-Z0-9\-_]+$/.test(name.trim())) {
alert('页面名称只允许字母、数字、短横线和下划线');
return;
}
try {
if (isEdit) {
await API.adminUpdateCustomPage(page.id, title.trim(), content.trim(), enabled);
} else {
await API.adminCreateCustomPage(name.trim(), title.trim(), content.trim());
}
onSaved();
} catch (err) {
alert('保存失败:' + err.message);
}
};
return (
<div className="modal active" style={{ display: 'flex' }} onClick={(e) => { if (e.target === e.currentTarget) onClose(); }}>
<div className="modal-content" style={{ maxWidth: 600, maxHeight: '90vh', overflowY: 'auto', position: 'relative' }}>
<span className="close" style={{ position: 'absolute', top: 12, right: 16, fontSize: 24, cursor: 'pointer', color: 'var(--text-light)' }} onClick={onClose}>&times;</span>
<h2 style={{ marginBottom: 16 }}>{isEdit ? '✏️ 编辑页面' : '📄 添加页面'}</h2>
<div style={{ marginBottom: 12 }}>
<label style={{ fontWeight: 600, fontSize: 14, display: 'block', marginBottom: 4 }}>页面名称</label>
<input
type="text"
value={name}
readOnly={isEdit}
placeholder="about (用于 URL: ?custom=about)"
style={{ width: '100%', padding: '8px 12px', border: '1px solid var(--border)', borderRadius: 4, fontSize: 14, background: isEdit ? 'var(--border-light)' : 'var(--bg)', color: 'var(--text)' }}
onChange={(e) => setName(e.target.value)}
/>
{isEdit
? <div style={{ fontSize: 12, color: 'var(--text-light)', marginTop: 2 }}>⚠️ 名称不可修改</div>
: <div style={{ fontSize: 12, color: 'var(--text-light)', marginTop: 2 }}>只允许字母、数字、短横线和下划线</div>}
</div>
<div style={{ marginBottom: 12 }}>
<label style={{ fontWeight: 600, fontSize: 14, display: 'block', marginBottom: 4 }}>导航栏显示名称</label>
<input
type="text"
value={title}
placeholder="关于我们"
style={{ width: '100%', padding: '8px 12px', border: '1px solid var(--border)', borderRadius: 4, fontSize: 14, background: 'var(--bg)', color: 'var(--text)' }}
onChange={(e) => setTitle(e.target.value)}
/>
</div>
<div style={{ marginBottom: 12 }}>
<label style={{ fontWeight: 600, fontSize: 14, display: 'block', marginBottom: 4 }}>状态</label>
<select
value={String(enabled)}
style={{ width: '100%', padding: '8px 12px', border: '1px solid var(--border)', borderRadius: 4, fontSize: 14, background: 'var(--bg)', color: 'var(--text)' }}
onChange={(e) => setEnabled(e.target.value === 'true')}
>
<option value="true">启用</option>
<option value="false">禁用</option>
</select>
</div>
<div style={{ marginBottom: 12 }}>
<label style={{ fontWeight: 600, fontSize: 14, display: 'block', marginBottom: 4 }}>页面内容(HTML + CSS + JS)</label>
<textarea
rows={12}
value={content}
style={{ width: '100%', padding: '8px 12px', border: '1px solid var(--border)', borderRadius: 4, fontSize: 13, fontFamily: 'monospace', background: 'var(--bg)', color: 'var(--text)', resize: 'vertical' }}
onChange={(e) => setContent(e.target.value)}
/>
<div style={{ fontSize: 12, color: 'var(--text-light)', marginTop: 2 }}>支持 HTML、CSS(&lt;style&gt;)、JS(&lt;script&gt;),内容会在独立的沙盒中渲染</div>
</div>
<button className="btn-primary" style={{ padding: '10px 24px', width: '100%' }} onClick={handleSave}>保存</button>
</div>
</div>
);
}