- Post 模型新增 IsLocked 字段,与 Status 解耦 - Lock 仅设 IsLocked=true(不改 Status),已通过帖子锁定后仍公开可见 - Unlock 仅设 IsLocked=false(不改 Status) - Update/EditPage 编辑检查改用 IsLocked 而非 Status==locked - Reject 与 Lock 独立,可单独退回或锁定+退回组合使用 - 新增 ErrPostCannotLock 错误哨兵 - 前端模板编辑按钮/锁定标识基于 IsLocked 渲染
83 lines
4.1 KiB
HTML
83 lines
4.1 KiB
HTML
{{template "admin/layout/base.html" .}}
|
|
<div class="page-header">
|
|
<h1>内容管理</h1>
|
|
<p class="page-desc">管理所有社区帖子</p>
|
|
</div>
|
|
|
|
<div class="admin-filter-bar">
|
|
<form class="filter-form" method="GET" action="/admin/posts">
|
|
<input type="text" name="keyword" value="{{.Keyword}}" placeholder="搜索标题..." class="form-input filter-input">
|
|
<select name="status" class="form-select filter-select">
|
|
<option value="">全部状态</option>
|
|
<option value="draft" {{if eq .Status "draft"}}selected{{end}}>草稿</option>
|
|
<option value="pending" {{if eq .Status "pending"}}selected{{end}}>待审核</option>
|
|
<option value="approved" {{if eq .Status "approved"}}selected{{end}}>已发布</option>
|
|
<option value="rejected" {{if eq .Status "rejected"}}selected{{end}}>已退回</option>
|
|
</select>
|
|
<button type="submit" class="btn btn-primary">搜索</button>
|
|
</form>
|
|
</div>
|
|
|
|
{{if .Error}}
|
|
<div class="error-message">{{.Error}}</div>
|
|
{{end}}
|
|
|
|
<table class="admin-table">
|
|
<thead>
|
|
<tr>
|
|
<th>ID</th>
|
|
<th>标题</th>
|
|
<th>作者</th>
|
|
<th>状态</th>
|
|
<th>时间</th>
|
|
<th>操作</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{{if eq (len .Posts) 0}}
|
|
<tr><td colspan="6" class="empty">暂无帖子</td></tr>
|
|
{{end}}
|
|
{{range .Posts}}
|
|
<tr class="post-row">
|
|
<td>{{.ID}}</td>
|
|
<td><a href="/posts/{{.ID}}" target="_blank" class="post-link">{{.Title}}</a></td>
|
|
<td>{{if .AuthorName}}{{.AuthorName}}({{.UserID}}){{else}}UID{{.UserID}}{{end}}</td>
|
|
<td><span class="status-badge status-{{.Status}}">{{index $.StatusNames .Status}}</span>{{if .IsLocked}} <span class="status-badge status-locked">已锁定</span>{{end}}</td>
|
|
<td>{{.CreatedAt.Format "2006-01-02 15:04"}}</td>
|
|
<td class="actions-cell">
|
|
<div class="action-btns">
|
|
{{if eq .Status "pending"}}
|
|
<button class="btn btn-sm btn-success post-approve" data-id="{{.ID}}">通过</button>
|
|
<button class="btn btn-sm btn-warning post-reject" data-id="{{.ID}}">退回</button>
|
|
{{end}}
|
|
{{if eq .Status "approved"}}
|
|
<button class="btn btn-sm btn-warning post-reject" data-id="{{.ID}}">退回</button>
|
|
{{end}}
|
|
{{if and (not .IsLocked) (ne .Status "pending")}}
|
|
<button class="btn btn-sm btn-danger post-lock" data-id="{{.ID}}">锁定</button>
|
|
{{end}}
|
|
{{if .IsLocked}}
|
|
<button class="btn btn-sm btn-success post-unlock" data-id="{{.ID}}">解锁</button>
|
|
{{end}}
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
{{end}}
|
|
</tbody>
|
|
</table>
|
|
|
|
{{if gt .TotalPages 1}}
|
|
<div class="pagination">
|
|
{{if gt .Page 1}}
|
|
<a href="?page={{.PrevPage}}{{if .Keyword}}&keyword={{.Keyword}}{{end}}{{if .Status}}&status={{.Status}}{{end}}" class="page-link">上一页</a>
|
|
{{end}}
|
|
<span class="page-info">第 {{.Page}} / {{.TotalPages}} 页 (共 {{.Total}} 条)</span>
|
|
{{if lt .Page .TotalPages}}
|
|
<a href="?page={{.NextPage}}{{if .Keyword}}&keyword={{.Keyword}}{{end}}{{if .Status}}&status={{.Status}}{{end}}" class="page-link">下一页</a>
|
|
{{end}}
|
|
</div>
|
|
{{end}}
|
|
|
|
<script src="/admin/static/js/posts.js"></script>
|
|
{{template "admin/layout/footer.html" .}}
|