feat: 新增创作中心(/studio),支持数据概览、内容管理、草稿箱、写文章
- 新增 StudioController,依赖 studioUseCase 接口,遵循 ISP 接口隔离 - PostRepo 新增 FindByUserIDAndStatus 方法,按用户+状态分页查询 - PostService 新增 ListByUser、GetOverview 及 StudioOverview 统计 - /studio 页面路由(概览/管理/草稿箱/写文章/数据分析)+ /api/studio API - 复用 Vditor 编辑器,studio-editor.js 对接 /api/studio/posts 端点 - 新增 studio.css(B站风格三栏布局+统计卡片+状态筛选tabs) - 模板引擎注册 add/subtract 函数,分页模板中直接使用
This commit is contained in:
105
templates/MetaLab-2026/html/studio/posts.html
Normal file
105
templates/MetaLab-2026/html/studio/posts.html
Normal file
@ -0,0 +1,105 @@
|
||||
{{template "layout/header.html" .}}
|
||||
<body>
|
||||
|
||||
{{template "layout/nav.html" .}}
|
||||
|
||||
<div class="studio-wrapper">
|
||||
{{template "studio/sidebar.html" .}}
|
||||
|
||||
<main class="studio-main">
|
||||
<div class="studio-header">
|
||||
<h1>内容管理</h1>
|
||||
{{if .Overview}}
|
||||
<div class="header-counts">
|
||||
<span class="header-count approved">已发布 {{.Overview.ApprovedCount}}</span>
|
||||
<span class="header-count pending">审核中 {{.Overview.PendingCount}}</span>
|
||||
<span class="header-count draft">草稿 {{.Overview.DraftCount}}</span>
|
||||
<span class="header-count rejected">已退回 {{.Overview.RejectedCount}}</span>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
{{if .Error}}
|
||||
<div class="studio-error">{{.Error}}</div>
|
||||
{{else}}
|
||||
<!-- 状态筛选 tabs -->
|
||||
<div class="status-tabs">
|
||||
<a href="/studio/posts" class="status-tab {{if not .CurrentStatus}}active{{end}}">全部</a>
|
||||
<a href="/studio/posts?status=approved" class="status-tab {{if eq .CurrentStatus "approved"}}active{{end}}">已发布</a>
|
||||
<a href="/studio/posts?status=pending" class="status-tab {{if eq .CurrentStatus "pending"}}active{{end}}">审核中</a>
|
||||
<a href="/studio/posts?status=draft" class="status-tab {{if eq .CurrentStatus "draft"}}active{{end}}">草稿</a>
|
||||
<a href="/studio/posts?status=rejected" class="status-tab {{if eq .CurrentStatus "rejected"}}active{{end}}">已退回</a>
|
||||
</div>
|
||||
|
||||
{{if .Posts}}
|
||||
<div class="post-list">
|
||||
{{range .Posts}}
|
||||
<div class="post-item">
|
||||
<div class="post-item-main">
|
||||
<a href="/posts/{{.ID}}" class="post-item-title" target="_blank">{{.Title}}</a>
|
||||
<div class="post-item-meta">
|
||||
<span class="post-status-badge status-{{.Status}}">{{index $.StatusNames .Status}}</span>
|
||||
<span>{{.CreatedAt.Format "2006-01-02 15:04"}}</span>
|
||||
{{if .RejectReason}}
|
||||
<span class="post-reject-hint">退回理由:{{.RejectReason}}</span>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="post-item-actions">
|
||||
<a href="/studio/write?id={{.ID}}" class="action-btn">编辑</a>
|
||||
<a href="/posts/{{.ID}}" target="_blank" class="action-btn">查看</a>
|
||||
<button class="action-btn danger" onclick="deletePost({{.ID}})" title="删除">删除</button>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
<!-- 分页 -->
|
||||
{{if gt .TotalPages 1}}
|
||||
<div class="pagination">
|
||||
{{if gt .Page 1}}
|
||||
<a href="/studio/posts?status={{$.CurrentStatus}}&page={{subtract .Page 1}}" class="page-btn">上一页</a>
|
||||
{{end}}
|
||||
<span class="page-info">第 {{.Page}} / {{.TotalPages}} 页(共 {{.Total}} 篇)</span>
|
||||
{{if lt .Page .TotalPages}}
|
||||
<a href="/studio/posts?status={{$.CurrentStatus}}&page={{add .Page 1}}" class="page-btn">下一页</a>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{else}}
|
||||
<div class="studio-empty">
|
||||
<p>还没有{{if .CurrentStatus}}{{index $.StatusNames .CurrentStatus}}{{end}}内容的文章</p>
|
||||
<a href="/studio/write" class="btn-primary">去写一篇</a>
|
||||
</div>
|
||||
{{end}}
|
||||
{{end}}
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function deletePost(id) {
|
||||
if (!confirm('确定要删除这篇文章吗?')) return;
|
||||
|
||||
fetch('/api/studio/posts/' + id, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': '{{.CSRFToken}}'
|
||||
}
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
location.reload();
|
||||
} else {
|
||||
alert(data.message || '删除失败');
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
{{template "layout/footer.html" .}}
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user