diff --git a/internal/controller/post_controller.go b/internal/controller/post_controller.go index a0cba2a..6f3a287 100644 --- a/internal/controller/post_controller.go +++ b/internal/controller/post_controller.go @@ -95,6 +95,11 @@ func (ctrl *PostController) ShowPage(c *gin.Context) { // 仅 approved 公开可见(作者本人 + moderator+ 可预览其他状态) if post.Status != model.PostStatusApproved && !ctrl.postService.IsPostAccessible(uid, role, post.UserID) { + // 未登录用户:引导登录后回到当前帖子 + if uid == 0 { + common.RedirectToLogin(c) + return + } c.HTML(http.StatusNotFound, "posts/404.html", common.BuildPageData(c, gin.H{ "Title": "未找到", })) diff --git a/templates/MetaLab-2026/html/posts/404.html b/templates/MetaLab-2026/html/posts/404.html index 8b35b83..921cbc3 100644 --- a/templates/MetaLab-2026/html/posts/404.html +++ b/templates/MetaLab-2026/html/posts/404.html @@ -3,9 +3,17 @@ {{template "layout/nav.html" .}}
-

404

-

帖子不存在或已被删除

- 返回帖子列表 +
+ + + +
+

页面未找到

+

该帖子可能已被删除、尚未发布,或您输入的地址有误

+
{{template "layout/footer.html" .}} diff --git a/templates/MetaLab-2026/static/css/posts.css b/templates/MetaLab-2026/static/css/posts.css index 01ea963..8b4988f 100644 --- a/templates/MetaLab-2026/static/css/posts.css +++ b/templates/MetaLab-2026/static/css/posts.css @@ -200,19 +200,67 @@ /* ========== 404 ========== */ .error-404 { text-align: center; - padding: 80px 0; + padding: 100px 0; + max-width: 480px; + margin: 0 auto; +} + +.error-404-icon { + color: #d1d5db; + margin-bottom: 24px; +} + +.error-404-icon svg { + width: 72px; + height: 72px; } .error-404 h1 { - font-size: 72px; - color: #d1d5db; - margin: 0; + font-size: 24px; + color: #374151; + margin: 0 0 8px; + font-weight: 600; } .error-404 p { - font-size: 18px; - color: #6b7280; - margin: 12px 0 24px; + font-size: 15px; + color: #9ca3af; + margin: 0 0 32px; + line-height: 1.6; +} + +.error-404-actions { + display: flex; + justify-content: center; + gap: 12px; +} + +.error-404-actions .btn { + padding: 10px 24px; + border-radius: 8px; + font-size: 14px; + text-decoration: none; + transition: all 0.2s; +} + +.error-404-actions .btn-primary { + background: #2563eb; + color: #fff; + border: none; +} + +.error-404-actions .btn-primary:hover { + background: #1d4ed8; +} + +.error-404-actions .btn-secondary { + background: #f3f4f6; + color: #374151; + border: 1px solid #e5e7eb; +} + +.error-404-actions .btn-secondary:hover { + background: #e5e7eb; } /* ========== 空状态 ========== */ diff --git a/templates/MetaLab-2026/static/js/login.js b/templates/MetaLab-2026/static/js/login.js index eb75b7c..5200c77 100644 --- a/templates/MetaLab-2026/static/js/login.js +++ b/templates/MetaLab-2026/static/js/login.js @@ -19,6 +19,19 @@ function getRedirect() { var m = window.location.search.match(/[?&]redirect=([^&]+)/); if (m) return decodeURIComponent(m[1]); + // 回退:如果来源页是本站页面,跳回来源页 + try { + var ref = document.referrer; + if (ref) { + var a = document.createElement('a'); + a.href = ref; + if (a.hostname === window.location.hostname && + a.pathname !== window.location.pathname && + a.pathname.indexOf('/auth/') !== 0) { + return a.pathname + a.search + a.hash; + } + } + } catch (e) {} return '/'; }