| 用户 |
角色 |
注册时间 |
@@ -65,7 +65,7 @@ export default function AdminUsers() {
{isAdmin ? '管理员' : '普通用户'}
diff --git a/components/chat/ChatManager.js b/components/chat/ChatManager.js
index 94d117d..956e2e1 100644
--- a/components/chat/ChatManager.js
+++ b/components/chat/ChatManager.js
@@ -4,6 +4,7 @@
import { useState, useEffect, useCallback } from 'react';
import { API } from '@/lib/api';
import { useApp } from '../AppProvider';
+import { Icon } from '../Icons';
import ConversationList from './ConversationList';
import ChatWindow from './ChatWindow';
@@ -33,7 +34,7 @@ export function DMButton() {
style={{ position: 'relative', padding: '6px 8px', background: 'none', border: 'none', cursor: 'pointer', color: 'var(--text-secondary)', borderRadius: 4, display: 'inline-flex', alignItems: 'center', justifyContent: 'center' }}
onClick={() => window.dispatchEvent(new CustomEvent('forumlify-open-messages'))}
>
- ✉️
+
{unread > 0 && (
{unread > 99 ? '99+' : unread}
diff --git a/lib/markdown.js b/lib/markdown.js
new file mode 100644
index 0000000..f6f74ba
--- /dev/null
+++ b/lib/markdown.js
@@ -0,0 +1,12 @@
+// Markdown 渲染工具(对齐上游 marked 行为)
+import { marked } from 'marked';
+
+// 渲染 markdown 为 HTML;失败时回退为纯文本换行
+export function renderMarkdown(text) {
+ if (!text) return '';
+ try {
+ return marked.parse(text);
+ } catch {
+ return text.replace(/\n/g, ' ');
+ }
+}
diff --git a/package.json b/package.json
index a86f34d..abb4e33 100644
--- a/package.json
+++ b/package.json
@@ -13,6 +13,7 @@
"aws4fetch": "^1.0.20",
"bcryptjs": "^3.0.3",
"jsonwebtoken": "^9.0.2",
+ "marked": "^18.0.9",
"next": "^14.2.15",
"pg": "^8.11.3",
"react": "^18.3.1",
From 83d270eada5b6dc1f3786721263da0b49c90f64f Mon Sep 17 00:00:00 2001
From: lezi-fun <177434121+lezi-fun@users.noreply.github.com>
Date: Mon, 10 Aug 2026 18:25:44 +0800
Subject: [PATCH 15/37] feat: theme follows system preference by default + fix
dark mode FOUC
- getTheme: manual localStorage override first, else prefers-color-scheme
- layout: inline head script sets data-theme before first paint (no
white flash in dark mode on loading screen)
- AppProvider: listen for system theme change when user hasn't overridden
---
app/layout.js | 16 ++++++++++++++++
components/AppProvider.js | 13 +++++++++++++
lib/api.js | 9 +++++++--
3 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/app/layout.js b/app/layout.js
index e5b9f06..ce8536f 100644
--- a/app/layout.js
+++ b/app/layout.js
@@ -11,6 +11,22 @@ export const metadata = {
export default function RootLayout({ children }) {
return (
+
+ {/* 首帧前同步主题,避免深色模式闪白(FOUC):手动设置优先,否则跟随系统 */}
+
+
{children}
diff --git a/components/AppProvider.js b/components/AppProvider.js
index 03a4e61..729970c 100644
--- a/components/AppProvider.js
+++ b/components/AppProvider.js
@@ -37,6 +37,19 @@ export default function AppProvider({ children }) {
const t = getTheme();
setThemeState(t);
document.documentElement.setAttribute('data-theme', t);
+ // 系统主题变化时跟随(仅当用户未手动设置过)
+ const mq = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)');
+ if (mq && mq.addEventListener) {
+ const onSysChange = () => {
+ if (!localStorage.getItem('forumlify-theme')) {
+ const next = mq.matches ? 'dark' : 'light';
+ setThemeState(next);
+ document.documentElement.setAttribute('data-theme', next);
+ }
+ };
+ mq.addEventListener('change', onSysChange);
+ return () => mq.removeEventListener('change', onSysChange);
+ }
}, []);
const toggleTheme = useCallback(() => {
diff --git a/lib/api.js b/lib/api.js
index 9cff7e1..727059d 100644
--- a/lib/api.js
+++ b/lib/api.js
@@ -195,8 +195,13 @@ export function generateCaptcha() {
return { question: a + ' ' + op + ' ' + b + ' = ?', answer: op === '+' ? a + b : a - b };
}
-// 主题
+// 主题:手动设置优先,否则跟随系统偏好
export function getTheme() {
if (typeof window === 'undefined') return 'light';
- return localStorage.getItem('forumlify-theme') || 'light';
+ const saved = localStorage.getItem('forumlify-theme');
+ if (saved) return saved;
+ if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
+ return 'dark';
+ }
+ return 'light';
}
From c059ad0979645b1f693189ce70507a7fac12c794 Mon Sep 17 00:00:00 2001
From: lezi-fun <177434121+lezi-fun@users.noreply.github.com>
Date: Mon, 10 Aug 2026 21:25:30 +0800
Subject: [PATCH 16/37] style: sync admin table full-width styles from upstream
---
app/globals.css | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/app/globals.css b/app/globals.css
index 752a851..5b3109f 100644
--- a/app/globals.css
+++ b/app/globals.css
@@ -2040,3 +2040,27 @@ a.btn-secondary {
border-top: 1px solid var(--glass-border);
margin: 14px 0;
}
+
+/* ============================================================
+ 管理后台 —— 表格撑满(同步上游)
+ ============================================================ */
+#adminContent {
+ width: 100% !important;
+ max-width: 100% !important;
+}
+
+#adminContent table {
+ width: 100% !important;
+ min-width: 100% !important;
+ table-layout: auto !important;
+}
+
+#adminContent th,
+#adminContent td {
+ white-space: nowrap !important;
+}
+
+#adminContent td:first-child,
+#adminContent td:nth-child(2) {
+ white-space: normal !important;
+}
From 80eb3136049e20a9f52b416d3079c7f7b8a289b7 Mon Sep 17 00:00:00 2001
From: lezi-fun <177434121+lezi-fun@users.noreply.github.com>
Date: Mon, 10 Aug 2026 21:54:28 +0800
Subject: [PATCH 17/37] feat: toast notifications, canvas captcha, super admin,
mobile fixes
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- Toast system (ToastProvider + useToast): right-top colored toasts
replace alert for publish success/error; CSS + layout mount
- Captcha as canvas image (noise + distortion) in NewPost/ReplyList/
register modal — blocks bots, click to refresh
- Super admin: first registered user cannot be demoted (isFirstUser by
created_at, DB-agnostic)
- Admins can delete others' posts/replies (UI buttons shown for admin)
- Mobile: post-actions wrap + compact, feed excerpt 2.5 lines
- Fix: missing sun icon in Icons (dark mode toggle showed nothing)
- Feed long posts: gradient fade mask instead of line-clamp
---
app/api/users/[id]/route.js | 6 ++-
app/globals.css | 75 ++++++++++++++++++++++++++++++++++---
app/layout.js | 7 +++-
components/CaptchaImage.js | 68 +++++++++++++++++++++++++++++++++
components/Feed.js | 20 ++++++++--
components/Icons.js | 5 +++
components/Modals.js | 13 ++++---
components/NewPost.js | 23 +++++++-----
components/PostDetail.js | 3 +-
components/ReplyList.js | 13 ++++---
components/Toast.js | 50 +++++++++++++++++++++++++
lib/auth.js | 10 +++++
12 files changed, 262 insertions(+), 31 deletions(-)
create mode 100644 components/CaptchaImage.js
create mode 100644 components/Toast.js
diff --git a/app/api/users/[id]/route.js b/app/api/users/[id]/route.js
index 826c157..848675d 100644
--- a/app/api/users/[id]/route.js
+++ b/app/api/users/[id]/route.js
@@ -1,6 +1,6 @@
// PUT /api/users/[id] (更新资料), PUT /api/users/[id]/role (改角色)
import pool from '@/lib/db';
-import { getUser, requireAdmin } from '@/lib/auth';
+import { getUser, requireAdmin, isFirstUser } from '@/lib/auth';
export async function PUT(req, { params }) {
const { id } = params;
@@ -22,6 +22,10 @@ export async function PUT(req, { params }) {
if (id === user.id) {
return Response.json({ error: '不能修改自己的角色' }, { status: 400 });
}
+ // 超级管理员(第一个用户)不能被降级
+ if (role !== 'admin' && await isFirstUser(id)) {
+ return Response.json({ error: '不能降级超级管理员' }, { status: 403 });
+ }
try {
await pool.query('UPDATE users SET role = $1 WHERE id = $2', [role, id]);
return Response.json({ success: true });
diff --git a/app/globals.css b/app/globals.css
index 5b3109f..b2779e7 100644
--- a/app/globals.css
+++ b/app/globals.css
@@ -1179,6 +1179,17 @@ svg {
width: 20px;
height: 20px;
}
+ /* 手机版帖子操作按钮紧凑排列,避免删除按钮越界 */
+ .post-actions {
+ gap: 8px;
+ flex-wrap: wrap;
+ }
+ .post-actions button {
+ padding: 4px 4px;
+ }
+ #feed .post-content {
+ max-height: 4.25em; /* 手机屏约 2.5 行 */
+ }
}
/* ============================================================
@@ -1907,15 +1918,24 @@ a.btn-secondary {
============================================================ */
#feed .post-content {
- display: -webkit-box;
- -webkit-line-clamp: 3;
- -webkit-box-orient: vertical;
+ position: relative;
+ max-height: 5.1em; /* 约 3 行(line-height 1.7) */
overflow: hidden;
- text-overflow: ellipsis;
- max-height: none;
line-height: 1.7;
}
+/* 长帖:底部渐变遮罩(提示还有更多内容) */
+#feed .post-content.has-fade::after {
+ content: '';
+ position: absolute;
+ bottom: 0;
+ left: 0;
+ right: 0;
+ height: 2.2em;
+ background: linear-gradient(180deg, transparent 0%, var(--glass-bg) 100%);
+ pointer-events: none;
+}
+
/* ===== 全屏加载页 ===== */
.loading-screen {
position: fixed;
@@ -2064,3 +2084,48 @@ a.btn-secondary {
#adminContent td:nth-child(2) {
white-space: normal !important;
}
+
+/* ===== Toast 通知(右上角,替代 alert) ===== */
+.toast-container {
+ position: fixed;
+ top: 20px;
+ right: 20px;
+ z-index: 100000;
+ display: flex;
+ flex-direction: column;
+ gap: 10px;
+ pointer-events: none;
+}
+
+.toast {
+ pointer-events: auto;
+ min-width: 200px;
+ max-width: 340px;
+ padding: 12px 18px;
+ border-radius: 10px;
+ font-size: 14px;
+ font-weight: 500;
+ color: #fff;
+ box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
+ backdrop-filter: blur(12px);
+ -webkit-backdrop-filter: blur(12px);
+ cursor: pointer;
+ animation: toastIn 0.25s cubic-bezier(0.22, 1, 0.36, 1);
+}
+
+.toast-success {
+ background: rgba(34, 197, 94, 0.92);
+}
+
+.toast-error {
+ background: rgba(239, 68, 68, 0.92);
+}
+
+.toast-info {
+ background: rgba(91, 155, 213, 0.92);
+}
+
+@keyframes toastIn {
+ from { opacity: 0; transform: translateX(24px); }
+ to { opacity: 1; transform: translateX(0); }
+}
diff --git a/app/layout.js b/app/layout.js
index ce8536f..43555e6 100644
--- a/app/layout.js
+++ b/app/layout.js
@@ -1,6 +1,7 @@
// 全局布局
import './globals.css';
import CustomCssLoader from '@/components/CustomCssLoader';
+import { ToastProvider } from '@/components/Toast';
export const metadata = {
// 初始标题由客户端 AppProvider 接管(加载时轮换 Loading.,完成后显示论坛名)
@@ -28,8 +29,10 @@ export default function RootLayout({ children }) {
/>
-
- {children}
+
+
+ {children}
+
);
diff --git a/components/CaptchaImage.js b/components/CaptchaImage.js
new file mode 100644
index 0000000..5f2e10f
--- /dev/null
+++ b/components/CaptchaImage.js
@@ -0,0 +1,68 @@
+'use client';
+
+// 图片验证码:用 canvas 绘制算式(带噪点/干扰线,挡一部分人机)
+// 点击图片可刷新验证码
+import { useEffect, useRef } from 'react';
+
+export default function CaptchaImage({ captcha, onRefresh }) {
+ const canvasRef = useRef(null);
+
+ useEffect(() => {
+ const canvas = canvasRef.current;
+ if (!canvas || !captcha) return;
+ const ctx = canvas.getContext('2d');
+ const W = canvas.width;
+ const H = canvas.height;
+
+ // 背景(半透明玻璃感)
+ ctx.clearRect(0, 0, W, H);
+ ctx.fillStyle = 'rgba(91, 155, 213, 0.10)';
+ ctx.fillRect(0, 0, W, H);
+
+ // 干扰线
+ for (let i = 0; i < 4; i++) {
+ ctx.strokeStyle = `rgba(${80 + Math.random() * 120}, ${80 + Math.random() * 120}, 200, ${0.2 + Math.random() * 0.3})`;
+ ctx.lineWidth = 1 + Math.random();
+ ctx.beginPath();
+ ctx.moveTo(Math.random() * W, Math.random() * H);
+ ctx.lineTo(Math.random() * W, Math.random() * H);
+ ctx.stroke();
+ }
+
+ // 噪点
+ for (let i = 0; i < 30; i++) {
+ ctx.fillStyle = `rgba(${Math.random() * 200}, ${Math.random() * 200}, 220, ${0.3 + Math.random() * 0.5})`;
+ ctx.beginPath();
+ ctx.arc(Math.random() * W, Math.random() * H, 1 + Math.random() * 1.5, 0, Math.PI * 2);
+ ctx.fill();
+ }
+
+ // 算式文字(每个字符轻微旋转/位移,增加识别难度)
+ const text = captcha.question.replace(' = ?', '');
+ const chars = text.split('');
+ const fontSize = Math.floor(H * 0.52);
+ const step = W / (chars.length + 1);
+ chars.forEach((ch, i) => {
+ ctx.save();
+ ctx.translate(step * (i + 1) + (Math.random() - 0.5) * 6, H / 2 + (Math.random() - 0.5) * 6);
+ ctx.rotate((Math.random() - 0.5) * 0.25);
+ ctx.font = `bold ${fontSize}px -apple-system, "SF Pro Display", "Segoe UI", Roboto, sans-serif`;
+ ctx.fillStyle = `rgba(${40 + Math.random() * 60}, ${50 + Math.random() * 50}, 90, 0.9)`;
+ ctx.textAlign = 'center';
+ ctx.textBaseline = 'middle';
+ ctx.fillText(ch, 0, 0);
+ ctx.restore();
+ });
+ }, [captcha]);
+
+ return (
+
+ );
+}
diff --git a/components/Feed.js b/components/Feed.js
index 7bdd7ce..60f517f 100644
--- a/components/Feed.js
+++ b/components/Feed.js
@@ -1,7 +1,7 @@
'use client';
// 信息流:帖子列表 + 排序 tab + 发布新帖按钮
-import { useEffect, useState, useCallback } from 'react';
+import { useEffect, useState, useCallback, useRef } from 'react';
import { API } from '@/lib/api';
import { useApp } from './AppProvider';
import { Icon } from './Icons';
@@ -21,6 +21,7 @@ export default function Feed({ onOpenModal, onReport }) {
const [page, setPage] = useState(1);
const [totalPages, setTotalPages] = useState(1);
const [viewerSrc, setViewerSrc] = useState(null);
+ const postListRef = useRef(null);
const PAGE_SIZE = 20;
const load = useCallback(async (targetPage) => {
@@ -39,6 +40,19 @@ export default function Feed({ onOpenModal, onReport }) {
useEffect(() => { load(page); }, [load]);
+ // 长帖内容:超过 3 行时加 .has-fade(底部渐变遮罩提示还有更多内容)
+ useEffect(() => {
+ if (!posts || posts.length === 0 || !postListRef.current) return;
+ const els = postListRef.current.querySelectorAll('.post-content');
+ els.forEach((el) => {
+ if (el.scrollHeight > el.clientHeight + 4) {
+ el.classList.add('has-fade');
+ } else {
+ el.classList.remove('has-fade');
+ }
+ });
+ }, [posts]);
+
// 排序切换时回第一页
useEffect(() => { setPage(1); }, [sort]);
@@ -69,7 +83,7 @@ export default function Feed({ onOpenModal, onReport }) {
发布新帖
-
+
{posts === null ? (
加载中...
) : error ? (
@@ -119,7 +133,7 @@ export default function Feed({ onOpenModal, onReport }) {
}}>
举报
- {currentUser && currentUser.id === p.user_id && (
+ {currentUser && (currentUser.id === p.user_id || currentUser.role === 'admin') && (
|