- 新增域能完整分层:EnergyLog/PostEnergizeLog/DailyExpSummary 模型、EnergyRepo、EnergyService、EnergyController/AdminEnergyController - 支持签到获取域能(+1)、帖子赋能(-1/-2)/被赋能(+1/+2)、改名扣能(-6)/退款(+6)、删帖扣能(-2) - 赋能单人单帖上限20域能,每日赋能获得经验上限50 - 管理员支持批量调整域能(owner)和查询域能日志(admin) - LV0用户(exp<1)禁止签到和发帖,余额为负可签到/被赋能/删帖但不能赋能/改名 - 首次改名免费(通过HasCompletedTask判重),改名扣能在提交审核时执行 - 移除导航栏手动签到按钮,签到融入域能系统(自动签到) - 新增个人中心域能TAB展示余额和流水日志(近7天) - 新增帖子详情页赋能按钮(轻赋/重赋) - 管理后台新增域能管理和域能日志页面
159 lines
5.9 KiB
HTML
159 lines
5.9 KiB
HTML
{{template "layout/header.html" .}}
|
||
<body>
|
||
|
||
{{template "layout/nav.html" .}}
|
||
|
||
<div class="container post-detail">
|
||
<article class="post-article">
|
||
<header class="post-detail-header">
|
||
<h1 class="post-detail-title">{{.Post.Title}}</h1>
|
||
<div class="post-detail-meta">
|
||
<span class="post-author">{{if .Post.AuthorName}}{{.Post.AuthorName}}{{else}}该用户已注销{{end}}</span>
|
||
<span class="post-time">{{.Post.CreatedAt.Format "2006-01-02 15:04"}}</span>
|
||
{{if ne .Post.Status "approved"}}
|
||
<span class="post-status post-status-{{.Post.Status}}">{{index $.StatusNames .Post.Status}}</span>
|
||
{{end}}
|
||
{{if .Post.IsLocked}}
|
||
<span class="post-status post-status-locked">已锁定</span>
|
||
{{end}}
|
||
{{if and .Post.PendingBody (eq $.Post.UserID $.UID)}}
|
||
<span class="post-status post-status-revision">修订审核中</span>
|
||
{{end}}
|
||
</div>
|
||
</header>
|
||
|
||
{{if .Post.RejectReason}}
|
||
<div class="post-reject-reason">
|
||
<strong>退回理由:</strong>{{.Post.RejectReason}}
|
||
</div>
|
||
{{end}}
|
||
|
||
<div class="post-detail-body" id="postContent"></div>
|
||
</article>
|
||
|
||
{{if .IsLoggedIn}}
|
||
<div class="post-actions">
|
||
{{if and $.Post (or (eq $.Post.UserID $.UID) $.CanAccessAdmin) (ne $.Post.Status "pending") (not $.Post.IsLocked)}}
|
||
<a href="/studio/write?id={{$.Post.ID}}" class="btn btn-secondary">编辑</a>
|
||
{{end}}
|
||
{{if and $.Post (eq $.Post.UserID $.UID) (or (eq $.Post.Status "draft") (eq $.Post.Status "rejected")) (not $.Post.IsLocked)}}
|
||
<button class="btn btn-primary" id="submitAuditBtn" data-id="{{$.Post.ID}}">提交审核</button>
|
||
{{end}}
|
||
{{if and $.Post (ne $.Post.UserID $.UID)}}
|
||
<button class="btn btn-primary" id="energizeBtn" data-id="{{$.Post.ID}}">赋能</button>
|
||
{{end}}
|
||
</div>
|
||
{{end}}
|
||
</div>
|
||
|
||
{{template "layout/footer.html" .}}
|
||
|
||
{{/* MD 内容安全传递给 JS */}}
|
||
<textarea id="postMdContent" style="display:none">{{.Post.Body}}</textarea>
|
||
|
||
<link rel="stylesheet" href="/static/vditor/dist/index.css?v={{assetV "/static/vditor/dist/index.css"}}">
|
||
<script src="/static/vditor/dist/method.min.js?v={{assetV "/static/vditor/dist/method.min.js"}}"></script>
|
||
<script src="/static/js/common.js?v={{assetV "/static/js/common.js"}}"></script>
|
||
<script src="/static/js/shortcode.js?v={{assetV "/static/js/shortcode.js"}}"></script>
|
||
<script>
|
||
(function() {
|
||
var el = document.getElementById('postContent');
|
||
var mdEl = document.getElementById('postMdContent');
|
||
if (!el || !mdEl) return;
|
||
|
||
var md = mdEl.value;
|
||
Vditor.preview(el, md, {
|
||
cdn: '/static/vditor',
|
||
theme: { current: 'light', path: '/static/vditor/dist/css/content-theme' },
|
||
hljs: { style: 'github-dark', enable: true },
|
||
after: function() {
|
||
// 外部链接自动加 nofollow + target="_blank",避免权重流失
|
||
var host = window.location.host;
|
||
var links = el.querySelectorAll('a[href^="http"]');
|
||
for (var i = 0; i < links.length; i++) {
|
||
var a = links[i];
|
||
if (a.host && a.host !== host) {
|
||
a.setAttribute('rel', 'nofollow noopener noreferrer');
|
||
a.setAttribute('target', '_blank');
|
||
}
|
||
}
|
||
}
|
||
});
|
||
|
||
// Vditor.preview() 渲染 MD,shortcode 占位 div 原样保留
|
||
// 渲染完成后,将占位 div 替换为对应卡片 UI
|
||
renderShortcodes(el);
|
||
})();
|
||
</script>
|
||
|
||
<script>
|
||
// 提交审核按钮
|
||
(function() {
|
||
var btn = document.getElementById('submitAuditBtn');
|
||
if (!btn) return;
|
||
btn.addEventListener('click', function() {
|
||
if (!confirm('确认提交审核?审核通过后将公开发布。')) return;
|
||
var csrf = document.querySelector('meta[name="csrf-token"]');
|
||
fetch('/api/posts/' + btn.dataset.id + '/submit', {
|
||
method: 'POST',
|
||
headers: {
|
||
'Content-Type': 'application/json',
|
||
'X-CSRF-Token': csrf ? csrf.getAttribute('content') : ''
|
||
}
|
||
})
|
||
.then(function(r) { return r.json(); })
|
||
.then(function(d) {
|
||
if (d.success) { window.location.reload(); }
|
||
else { alert(d.message || '提交失败'); }
|
||
})
|
||
.catch(function() { alert('请求失败'); });
|
||
});
|
||
})();
|
||
</script>
|
||
|
||
<script>
|
||
// 赋能按钮
|
||
(function() {
|
||
var btn = document.getElementById('energizeBtn');
|
||
if (!btn) return;
|
||
btn.addEventListener('click', function() {
|
||
var postId = btn.dataset.id;
|
||
var choice = confirm('为这篇文章注入能量\n\n选择「确定」轻赋 1 域能,选择「取消」则打开重赋选项');
|
||
var amount = 20; // 重赋 2 域能
|
||
if (choice) {
|
||
amount = 10; // 轻赋 1 域能
|
||
}
|
||
|
||
var csrf = document.querySelector('meta[name="csrf-token"]');
|
||
btn.disabled = true;
|
||
btn.textContent = '赋能中...';
|
||
|
||
fetch('/api/energy/energize', {
|
||
method: 'POST',
|
||
headers: {
|
||
'Content-Type': 'application/json',
|
||
'X-CSRF-Token': csrf ? csrf.getAttribute('content') : ''
|
||
},
|
||
body: JSON.stringify({ post_id: parseInt(postId), amount: amount })
|
||
})
|
||
.then(function(r) { return r.json(); })
|
||
.then(function(d) {
|
||
btn.disabled = false;
|
||
btn.textContent = '赋能';
|
||
if (d.success) {
|
||
alert(d.data.message || '赋能成功!');
|
||
} else {
|
||
alert(d.message || '赋能失败');
|
||
}
|
||
})
|
||
.catch(function() {
|
||
btn.disabled = false;
|
||
btn.textContent = '赋能';
|
||
alert('请求失败');
|
||
});
|
||
});
|
||
})();
|
||
</script>
|
||
</body>
|
||
</html>
|