feat: toast notifications, canvas captcha, super admin, mobile fixes

- 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
This commit is contained in:
lezi-fun committed 2026-08-10 21:56:05 +08:00
1 parent c059ad0979
commit 80eb313604
12 files changed
+262 -31

No files matched your search

+5 -1
View File
@@ -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 });
+70 -5
View File
@@ -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); }
}
+5 -2
View File
@@ -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 }) {
/>
</head>
<body>
<CustomCssLoader />
{children}
<ToastProvider>
<CustomCssLoader />
{children}
</ToastProvider>
</body>
</html>
);