初始提交:姜十三论坛 Jiang13 Forum
轻量自用论坛,Go 单二进制 + React SPA 内嵌 + SQLite。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
95
embed_static/templates/admin/boards.html
Normal file
95
embed_static/templates/admin/boards.html
Normal file
@@ -0,0 +1,95 @@
|
||||
{{define "admin/boards.html"}}{{template "admin/layout" .}}{{end}}
|
||||
{{define "admin_content_boards"}}
|
||||
<div class="admin-page-head">
|
||||
<div>
|
||||
<h1>板块管理</h1>
|
||||
<p>创建和维护论坛板块,有帖子的板块无法删除</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="admin-card">
|
||||
<div class="admin-card-head">新建板块</div>
|
||||
<div class="admin-card-body">
|
||||
<form id="createBoardForm" class="row g-2 align-items-end">
|
||||
<div class="col-md-3">
|
||||
<label class="form-label small">板块名称</label>
|
||||
<input name="name" class="form-control" placeholder="如:技术交流" required maxlength="64">
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label small">简介</label>
|
||||
<input name="description" class="form-control" placeholder="板块说明(可选)" maxlength="500">
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<label class="form-label small">排序</label>
|
||||
<input name="sort_order" type="number" class="form-control" value="0">
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<button type="submit" class="btn btn-success w-100" id="createBoardBtn">创建板块</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="admin-card">
|
||||
<div class="admin-card-head">板块列表 <span class="text-muted fw-normal">共 {{len .Boards}} 个</span></div>
|
||||
<div class="table-responsive">
|
||||
<table class="table admin-table mb-0">
|
||||
<thead><tr><th>ID</th><th>名称</th><th>描述</th><th>排序</th><th>帖子数</th><th width="160">操作</th></tr></thead>
|
||||
<tbody>
|
||||
{{range .Boards}}
|
||||
<tr>
|
||||
<td>{{.ID}}</td>
|
||||
<td><input class="form-control form-control-sm" id="name-{{.ID}}" value="{{.Name}}"></td>
|
||||
<td><input class="form-control form-control-sm" id="desc-{{.ID}}" value="{{.Description}}"></td>
|
||||
<td><input class="form-control form-control-sm" id="sort-{{.ID}}" type="number" value="{{.SortOrder}}" style="width:72px"></td>
|
||||
<td><span class="badge bg-secondary">{{.PostCount}}</span></td>
|
||||
<td>
|
||||
<button class="btn btn-sm btn-primary" onclick="updateBoard({{.ID}}, this)">保存</button>
|
||||
<button class="btn btn-sm btn-outline-danger" onclick="deleteBoard({{.ID}}, {{.PostCount}})">删除</button>
|
||||
</td>
|
||||
</tr>
|
||||
{{else}}
|
||||
<tr><td colspan="6" class="admin-empty">还没有板块,请先创建</td></tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{define "admin_scripts_boards"}}
|
||||
<script>
|
||||
document.getElementById('createBoardForm').addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
var btn = document.getElementById('createBoardBtn');
|
||||
setBtnLoading(btn, true);
|
||||
adminFetch('/admin/api/boards', { method: 'POST', body: new FormData(this) })
|
||||
.then(function(d) { showToast(d.message); reloadSoon(); })
|
||||
.catch(function(e) { showToast(e.message, 'danger'); })
|
||||
.finally(function() { setBtnLoading(btn, false); });
|
||||
});
|
||||
|
||||
function updateBoard(id, btn) {
|
||||
setBtnLoading(btn, true);
|
||||
postForm('/admin/api/boards/' + id, 'PUT', {
|
||||
name: document.getElementById('name-' + id).value,
|
||||
description: document.getElementById('desc-' + id).value,
|
||||
sort_order: document.getElementById('sort-' + id).value
|
||||
}).then(function(d) { showToast(d.message); })
|
||||
.catch(function(e) { showToast(e.message, 'danger'); })
|
||||
.finally(function() { setBtnLoading(btn, false); });
|
||||
}
|
||||
|
||||
function deleteBoard(id, postCount) {
|
||||
if (postCount > 0) {
|
||||
showToast('该板块下还有 ' + postCount + ' 篇帖子,无法删除', 'warning');
|
||||
return;
|
||||
}
|
||||
adminConfirm('确定删除该板块?此操作不可恢复。', function() {
|
||||
adminFetch('/admin/api/boards/' + id, { method: 'DELETE' })
|
||||
.then(function(d) { showToast(d.message); reloadSoon(); })
|
||||
.catch(function(e) { showToast(e.message, 'danger'); });
|
||||
});
|
||||
}
|
||||
</script>
|
||||
{{end}}
|
||||
58
embed_static/templates/admin/comments.html
Normal file
58
embed_static/templates/admin/comments.html
Normal file
@@ -0,0 +1,58 @@
|
||||
{{define "admin/comments.html"}}{{template "admin/layout" .}}{{end}}
|
||||
{{define "admin_content_comments"}}
|
||||
<div class="admin-page-head">
|
||||
<div>
|
||||
<h1>评论管理</h1>
|
||||
<p>查看和删除评论,共 {{.Total}} 条</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="admin-card">
|
||||
<div class="table-responsive">
|
||||
<table class="table admin-table mb-0">
|
||||
<thead>
|
||||
<tr><th>ID</th><th>楼层</th><th>帖子</th><th>作者</th><th>回复</th><th>内容</th><th>时间</th><th width="100">操作</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{range .Comments}}
|
||||
<tr>
|
||||
<td>{{.ID}}</td>
|
||||
<td>#{{.Floor}}</td>
|
||||
<td class="text-truncate-cell">
|
||||
{{if .Post}}
|
||||
<a href="/post/{{.PostID}}" target="_blank">{{.Post.Title}}</a>
|
||||
{{else}}帖子 #{{.PostID}}{{end}}
|
||||
</td>
|
||||
<td>{{if .UserID}}{{if .User}}{{.User.Nickname}}{{else}}-{{end}}{{else}}{{.GuestNick}}{{end}}</td>
|
||||
<td>
|
||||
{{if .ReplyTarget}}
|
||||
@{{if .ReplyTarget.UserID}}{{if .ReplyTarget.User}}{{.ReplyTarget.User.Nickname}}{{else}}-{{end}}{{else}}{{.ReplyTarget.GuestNick}}{{end}}
|
||||
{{else}}-{{end}}
|
||||
</td>
|
||||
<td class="text-truncate-cell">{{.Content}}</td>
|
||||
<td>{{.CreatedAt.Format "01-02 15:04"}}</td>
|
||||
<td>
|
||||
<button class="btn btn-sm btn-outline-danger" onclick="deleteComment({{.ID}})">删除</button>
|
||||
</td>
|
||||
</tr>
|
||||
{{else}}
|
||||
<tr><td colspan="8" class="admin-empty">暂无评论</td></tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{{template "admin_pagination" .}}
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{define "admin_scripts_comments"}}
|
||||
<script>
|
||||
function deleteComment(id) {
|
||||
adminConfirm('确定删除该评论?', function() {
|
||||
adminFetch('/admin/api/comments/' + id, { method: 'DELETE' })
|
||||
.then(function(d) { showToast(d.message); reloadSoon(); })
|
||||
.catch(function(e) { showToast(e.message, 'danger'); });
|
||||
});
|
||||
}
|
||||
</script>
|
||||
{{end}}
|
||||
76
embed_static/templates/admin/dashboard.html
Normal file
76
embed_static/templates/admin/dashboard.html
Normal file
@@ -0,0 +1,76 @@
|
||||
{{define "admin/dashboard.html"}}{{template "admin/layout" .}}{{end}}
|
||||
{{define "admin_content_dashboard"}}
|
||||
<div class="admin-page-head">
|
||||
<div>
|
||||
<h1>仪表盘</h1>
|
||||
<p>欢迎回来{{if .CurrentUser}},{{.CurrentUser.Nickname}}{{end}} · 论坛运行概况</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="admin-stat-grid">
|
||||
<div class="admin-stat-card admin-stat-users">
|
||||
<div class="admin-stat-icon">用</div>
|
||||
<div class="admin-stat-info">
|
||||
<div class="value">{{.UserCount}}</div>
|
||||
<div class="label">注册用户</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-stat-card admin-stat-posts">
|
||||
<div class="admin-stat-icon">帖</div>
|
||||
<div class="admin-stat-info">
|
||||
<div class="value">{{.PostCount}}</div>
|
||||
<div class="label">帖子总数</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-stat-card admin-stat-boards">
|
||||
<div class="admin-stat-icon">板</div>
|
||||
<div class="admin-stat-info">
|
||||
<div class="value">{{.BoardCount}}</div>
|
||||
<div class="label">板块数量</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-stat-card admin-stat-comments">
|
||||
<div class="admin-stat-icon">评</div>
|
||||
<div class="admin-stat-info">
|
||||
<div class="value">{{.CommentCount}}</div>
|
||||
<div class="label">评论总数</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-stat-card admin-stat-online">
|
||||
<div class="admin-stat-icon">线</div>
|
||||
<div class="admin-stat-info">
|
||||
<div class="value">{{.OnlineCount}}</div>
|
||||
<div class="label">当前浏览</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="admin-card">
|
||||
<div class="admin-card-head">
|
||||
<span>最近帖子</span>
|
||||
<a href="/admin/posts" class="admin-card-link">查看全部 →</a>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table admin-table mb-0">
|
||||
<thead><tr><th>标题</th><th>板块</th><th>作者</th><th>时间</th><th width="80"></th></tr></thead>
|
||||
<tbody>
|
||||
{{range .RecentPosts}}
|
||||
<tr>
|
||||
<td class="text-truncate-cell">
|
||||
{{if .Pinned}}<span class="badge badge-pin me-1">置顶</span>{{end}}{{.Title}}
|
||||
</td>
|
||||
<td>{{if .Board}}{{.Board.Name}}{{else}}-{{end}}</td>
|
||||
<td>{{if .User}}{{.User.Nickname}}{{else}}-{{end}}</td>
|
||||
<td class="text-muted">{{.CreatedAt.Format "01-02 15:04"}}</td>
|
||||
<td><a href="/post/{{.ID}}" target="_blank" class="btn btn-sm btn-link px-0">查看</a></td>
|
||||
</tr>
|
||||
{{else}}
|
||||
<tr><td colspan="5" class="admin-empty">暂无帖子</td></tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{define "admin_scripts_dashboard"}}{{end}}
|
||||
88
embed_static/templates/admin/layout.html
Normal file
88
embed_static/templates/admin/layout.html
Normal file
@@ -0,0 +1,88 @@
|
||||
{{define "admin/layout"}}
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>{{.Title}} - 姜十三论坛管理后台</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="/legacy/css/style.css" rel="stylesheet">
|
||||
</head>
|
||||
<body class="admin-body">
|
||||
<div class="toast-container position-fixed top-0 end-0 p-3" style="z-index:9999">
|
||||
<div id="adminToast" class="toast" role="alert">
|
||||
<div class="d-flex">
|
||||
<div class="toast-body"></div>
|
||||
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast"></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<header class="admin-topbar">
|
||||
<div class="admin-topbar-brand">
|
||||
<div class="admin-topbar-mark">姜</div>
|
||||
<div>
|
||||
<span class="admin-topbar-title">姜十三论坛</span>
|
||||
<span class="admin-topbar-sub">管理后台</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-topbar-actions">
|
||||
{{if .CurrentUser}}
|
||||
<span class="admin-topbar-user">{{.CurrentUser.Nickname}}</span>
|
||||
{{end}}
|
||||
<a href="/" class="btn btn-outline-light btn-sm">返回前台</a>
|
||||
<button class="btn btn-light btn-sm" onclick="adminLogout()">退出</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="admin-shell">
|
||||
<aside class="admin-sidebar">
|
||||
<div class="admin-sidebar-section">概览</div>
|
||||
<a href="/admin/dashboard" class="nav-link {{if eq .ActiveNav "dashboard"}}active{{end}}">仪表盘</a>
|
||||
|
||||
<div class="admin-sidebar-section">内容</div>
|
||||
<a href="/admin/boards" class="nav-link {{if eq .ActiveNav "boards"}}active{{end}}">板块管理</a>
|
||||
<a href="/admin/posts" class="nav-link {{if eq .ActiveNav "posts"}}active{{end}}">帖子管理</a>
|
||||
<a href="/admin/comments" class="nav-link {{if eq .ActiveNav "comments"}}active{{end}}">评论管理</a>
|
||||
|
||||
<div class="admin-sidebar-section">系统</div>
|
||||
<a href="/admin/users" class="nav-link {{if eq .ActiveNav "users"}}active{{end}}">用户管理</a>
|
||||
<a href="/admin/settings" class="nav-link {{if eq .ActiveNav "settings"}}active{{end}}">系统设置</a>
|
||||
</aside>
|
||||
|
||||
<main class="admin-main">
|
||||
{{if eq .ActiveNav "dashboard"}}{{template "admin_content_dashboard" .}}
|
||||
{{else if eq .ActiveNav "boards"}}{{template "admin_content_boards" .}}
|
||||
{{else if eq .ActiveNav "posts"}}{{template "admin_content_posts" .}}
|
||||
{{else if eq .ActiveNav "comments"}}{{template "admin_content_comments" .}}
|
||||
{{else if eq .ActiveNav "users"}}{{template "admin_content_users" .}}
|
||||
{{else if eq .ActiveNav "settings"}}{{template "admin_content_settings" .}}
|
||||
{{end}}
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="/legacy/js/app.js"></script>
|
||||
{{if eq .ActiveNav "boards"}}{{template "admin_scripts_boards" .}}
|
||||
{{else if eq .ActiveNav "posts"}}{{template "admin_scripts_posts" .}}
|
||||
{{else if eq .ActiveNav "comments"}}{{template "admin_scripts_comments" .}}
|
||||
{{else if eq .ActiveNav "users"}}{{template "admin_scripts_users" .}}
|
||||
{{else if eq .ActiveNav "settings"}}{{template "admin_scripts_settings" .}}
|
||||
{{end}}
|
||||
</body>
|
||||
</html>
|
||||
{{end}}
|
||||
|
||||
{{define "admin_pagination"}}
|
||||
{{if gt .TotalPages 1}}
|
||||
<nav class="admin-pagination">
|
||||
{{if gt .Page 1}}
|
||||
<a class="btn btn-sm btn-outline-secondary" href="?page={{sub .Page 1}}{{if .Keyword}}&keyword={{.Keyword}}{{end}}">上一页</a>
|
||||
{{end}}
|
||||
<span class="admin-pagination-info">第 {{.Page}} / {{.TotalPages}} 页</span>
|
||||
{{if lt .Page .TotalPages}}
|
||||
<a class="btn btn-sm btn-outline-secondary" href="?page={{add .Page 1}}{{if .Keyword}}&keyword={{.Keyword}}{{end}}">下一页</a>
|
||||
{{end}}
|
||||
</nav>
|
||||
{{end}}
|
||||
{{end}}
|
||||
49
embed_static/templates/admin/login.html
Normal file
49
embed_static/templates/admin/login.html
Normal file
@@ -0,0 +1,49 @@
|
||||
{{define "admin/login.html"}}
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>后台登录 - 姜十三论坛</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="/legacy/css/style.css" rel="stylesheet">
|
||||
</head>
|
||||
<body class="admin-login-page">
|
||||
<div class="admin-login-card">
|
||||
<div class="admin-login-mark">姜</div>
|
||||
<h4 class="text-center mb-1">管理后台登录</h4>
|
||||
<p class="login-slogan text-center mb-4">姜十三论坛 · 仅管理员可访问</p>
|
||||
{{if eq .QueryBanned "1"}}
|
||||
<div class="alert alert-warning small py-2">账号已被禁言,无法登录后台</div>
|
||||
{{end}}
|
||||
<form id="adminLoginForm">
|
||||
<div class="mb-2">
|
||||
<label class="form-label small">管理员账号</label>
|
||||
<input type="text" name="username" class="form-control" placeholder="用户名" required autofocus>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label small">密码</label>
|
||||
<input type="password" name="password" class="form-control" placeholder="密码" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-success w-100" id="loginBtn">登录</button>
|
||||
</form>
|
||||
<p class="text-center mt-3 mb-0 small">
|
||||
<a href="/" class="text-muted">← 返回论坛前台</a>
|
||||
</p>
|
||||
</div>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="/legacy/js/app.js"></script>
|
||||
<script>
|
||||
document.getElementById('adminLoginForm').addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
var btn = document.getElementById('loginBtn');
|
||||
setBtnLoading(btn, true);
|
||||
adminFetch('/admin/api/login', { method: 'POST', body: new FormData(this) })
|
||||
.then(function() { location.href = '/admin/dashboard'; })
|
||||
.catch(function(err) { alert(err.message); })
|
||||
.finally(function() { setBtnLoading(btn, false); });
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
{{end}}
|
||||
67
embed_static/templates/admin/posts.html
Normal file
67
embed_static/templates/admin/posts.html
Normal file
@@ -0,0 +1,67 @@
|
||||
{{define "admin/posts.html"}}{{template "admin/layout" .}}{{end}}
|
||||
{{define "admin_content_posts"}}
|
||||
<div class="admin-page-head">
|
||||
<div>
|
||||
<h1>帖子管理</h1>
|
||||
<p>置顶、删除帖子,共 {{.Total}} 篇</p>
|
||||
</div>
|
||||
<form class="admin-search-bar" method="get">
|
||||
<input name="keyword" class="form-control form-control-sm" placeholder="搜索标题/内容..." value="{{.Keyword}}">
|
||||
<button class="btn btn-sm btn-success">搜索</button>
|
||||
{{if .Keyword}}<a href="/admin/posts" class="btn btn-sm btn-outline-secondary">清除</a>{{end}}
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="admin-card">
|
||||
<div class="table-responsive">
|
||||
<table class="table admin-table mb-0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th><th>标题</th><th>板块</th><th>作者</th>
|
||||
<th>置顶</th><th>点赞</th><th>浏览</th><th>时间</th><th width="180">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{range .Posts}}
|
||||
<tr id="post-row-{{.ID}}">
|
||||
<td>{{.ID}}</td>
|
||||
<td class="text-truncate-cell">{{.Title}}</td>
|
||||
<td>{{if .Board}}{{.Board.Name}}{{else}}-{{end}}</td>
|
||||
<td>{{if .User}}{{.User.Nickname}}{{else}}-{{end}}</td>
|
||||
<td>{{if .Pinned}}<span class="badge badge-pin">是</span>{{else}}<span class="text-muted">否</span>{{end}}</td>
|
||||
<td>{{.LikeCount}}</td>
|
||||
<td>{{.ViewCount}}</td>
|
||||
<td>{{.CreatedAt.Format "01-02 15:04"}}</td>
|
||||
<td>
|
||||
<a href="/post/{{.ID}}" target="_blank" class="btn btn-sm btn-link">查看</a>
|
||||
<button class="btn btn-sm btn-outline-warning" onclick="togglePin({{.ID}}, {{.Pinned}})">{{if .Pinned}}取消置顶{{else}}置顶{{end}}</button>
|
||||
<button class="btn btn-sm btn-outline-danger" onclick="deletePost({{.ID}})">删除</button>
|
||||
</td>
|
||||
</tr>
|
||||
{{else}}
|
||||
<tr><td colspan="9" class="admin-empty">没有找到帖子</td></tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{{template "admin_pagination" .}}
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{define "admin_scripts_posts"}}
|
||||
<script>
|
||||
function togglePin(id, pinned) {
|
||||
postForm('/admin/api/posts/' + id + '/pin', 'POST', { pinned: pinned ? 'false' : 'true' })
|
||||
.then(function(d) { showToast(d.message); reloadSoon(); })
|
||||
.catch(function(e) { showToast(e.message, 'danger'); });
|
||||
}
|
||||
|
||||
function deletePost(id) {
|
||||
adminConfirm('确定删除该帖子?相关评论也将一并删除。', function() {
|
||||
adminFetch('/admin/api/posts/' + id, { method: 'DELETE' })
|
||||
.then(function(d) { showToast(d.message); reloadSoon(); })
|
||||
.catch(function(e) { showToast(e.message, 'danger'); });
|
||||
});
|
||||
}
|
||||
</script>
|
||||
{{end}}
|
||||
56
embed_static/templates/admin/settings.html
Normal file
56
embed_static/templates/admin/settings.html
Normal file
@@ -0,0 +1,56 @@
|
||||
{{define "admin/settings.html"}}{{template "admin/layout" .}}{{end}}
|
||||
{{define "admin_content_settings"}}
|
||||
<div class="admin-page-head">
|
||||
<div>
|
||||
<h1>系统设置</h1>
|
||||
<p>数据目录、敏感词配置与数据库备份</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row g-3">
|
||||
<div class="col-lg-6">
|
||||
<div class="admin-card">
|
||||
<div class="admin-card-head">运行信息</div>
|
||||
<div class="admin-card-body">
|
||||
<div class="info-row"><div class="info-label">数据目录</div><div class="info-value"><code>{{.DataDir}}</code></div></div>
|
||||
<div class="info-row"><div class="info-label">数据库文件</div><div class="info-value"><code>{{.DBPath}}</code></div></div>
|
||||
<div class="info-row"><div class="info-label">监听端口</div><div class="info-value">{{.Port}}</div></div>
|
||||
<div class="info-row"><div class="info-label">敏感词配置</div><div class="info-value"><code>{{.FilterPath}}</code></div></div>
|
||||
<p class="text-muted small mt-3 mb-0">敏感词文件每行一个词,<code>#</code> 开头为注释,修改后需重启服务生效。</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-6">
|
||||
<div class="admin-card">
|
||||
<div class="admin-card-head">数据库备份</div>
|
||||
<div class="admin-card-body">
|
||||
<p class="text-muted small">将 SQLite 数据库复制到数据目录,生成带时间戳的备份文件。</p>
|
||||
<button class="btn btn-success" id="backupBtn" onclick="doBackup()">一键导出备份</button>
|
||||
<div id="backupResult" class="mt-3"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{define "admin_scripts_settings"}}
|
||||
<script>
|
||||
function doBackup() {
|
||||
var btn = document.getElementById('backupBtn');
|
||||
setBtnLoading(btn, true);
|
||||
adminFetch('/admin/api/backup', { method: 'POST' })
|
||||
.then(function(d) {
|
||||
showToast(d.message);
|
||||
var html = '<div class="alert alert-success small mb-0">';
|
||||
html += '<div>备份文件:<code>' + d.filename + '</code></div>';
|
||||
if (d.download) {
|
||||
html += '<a href="' + d.download + '" class="btn btn-sm btn-outline-success mt-2">下载备份文件</a>';
|
||||
}
|
||||
html += '<div class="text-muted mt-2">存储路径:' + d.path + '</div></div>';
|
||||
document.getElementById('backupResult').innerHTML = html;
|
||||
})
|
||||
.catch(function(e) { showToast(e.message, 'danger'); })
|
||||
.finally(function() { setBtnLoading(btn, false); });
|
||||
}
|
||||
</script>
|
||||
{{end}}
|
||||
62
embed_static/templates/admin/users.html
Normal file
62
embed_static/templates/admin/users.html
Normal file
@@ -0,0 +1,62 @@
|
||||
{{define "admin/users.html"}}{{template "admin/layout" .}}{{end}}
|
||||
{{define "admin_content_users"}}
|
||||
<div class="admin-page-head">
|
||||
<div>
|
||||
<h1>用户管理</h1>
|
||||
<p>禁言违规用户,共 {{.Total}} 位注册用户</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="admin-card">
|
||||
<div class="table-responsive">
|
||||
<table class="table admin-table mb-0">
|
||||
<thead>
|
||||
<tr><th>ID</th><th>用户名</th><th>昵称</th><th>角色</th><th>状态</th><th>注册时间</th><th width="120">操作</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{range .Users}}
|
||||
<tr>
|
||||
<td>{{.ID}}</td>
|
||||
<td>{{.Username}}</td>
|
||||
<td>{{.Nickname}}</td>
|
||||
<td>
|
||||
{{if eq .Role "admin"}}
|
||||
<span class="badge badge-admin">管理员</span>
|
||||
{{else}}普通用户{{end}}
|
||||
</td>
|
||||
<td>
|
||||
{{if .Banned}}<span class="badge badge-banned">已禁言</span>{{else}}<span class="text-success">正常</span>{{end}}
|
||||
</td>
|
||||
<td>{{.CreatedAt.Format "2006-01-02"}}</td>
|
||||
<td>
|
||||
{{if eq .Role "admin"}}
|
||||
<span class="text-muted small">—</span>
|
||||
{{else if .Banned}}
|
||||
<button class="btn btn-sm btn-success" onclick="banUser({{.ID}}, false)">解除禁言</button>
|
||||
{{else}}
|
||||
<button class="btn btn-sm btn-outline-warning" onclick="banUser({{.ID}}, true)">禁言</button>
|
||||
{{end}}
|
||||
</td>
|
||||
</tr>
|
||||
{{else}}
|
||||
<tr><td colspan="7" class="admin-empty">暂无用户</td></tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{{template "admin_pagination" .}}
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{define "admin_scripts_users"}}
|
||||
<script>
|
||||
function banUser(id, banned) {
|
||||
var msg = banned ? '确定禁言该用户?禁言后无法登录和发帖。' : '确定解除该用户的禁言?';
|
||||
adminConfirm(msg, function() {
|
||||
postForm('/admin/api/users/' + id + '/ban', 'POST', { banned: banned ? 'true' : 'false' })
|
||||
.then(function(d) { showToast(d.message); reloadSoon(); })
|
||||
.catch(function(e) { showToast(e.message, 'danger'); });
|
||||
});
|
||||
}
|
||||
</script>
|
||||
{{end}}
|
||||
Reference in New Issue
Block a user