- utils.js getCSRFToken() 改为从 cookie 优先读取,meta 标签作为后备
- show.html 5处移除 csrfToken 缓存变量,改用 getCSRFToken() 动态获取
- studio/posts.html/drafts.html 移除 {{ .CSRFToken }} 模板硬编码
- studio-editor.js 移除本地 getCsrfToken(),改用共享 getCSRFToken()
- settings/index.html messages/index.html 改用 getCSRFToken()
- admin posts.js/comments.js 移除本地/死代码 CSRF 获取,统一用共享方法
61 lines
2.2 KiB
JavaScript
61 lines
2.2 KiB
JavaScript
(function() {
|
|
// CSRF token 由 shared/utils.js 的 getCSRFToken() 统一提供
|
|
|
|
function api(url, method, body) {
|
|
return fetch(url, {
|
|
method: method,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-CSRF-Token': getCSRFToken()
|
|
},
|
|
body: body ? JSON.stringify(body) : undefined
|
|
}).then(function(r) { return r.json(); });
|
|
}
|
|
|
|
function refreshPage() { window.location.reload(); }
|
|
|
|
function handleClick(sel, actionFn) {
|
|
var btns = document.querySelectorAll(sel);
|
|
btns.forEach(function(btn) {
|
|
btn.addEventListener('click', function() {
|
|
var id = btn.getAttribute('data-id');
|
|
if (confirm('确定执行此操作吗?')) {
|
|
actionFn(id);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
// 审核通过
|
|
handleClick('.post-approve', function(id) {
|
|
api('/api/admin/posts/' + id + '/approve', 'POST')
|
|
.then(function(d) { if (d.success) refreshPage(); else alert(d.message); })
|
|
.catch(function() { alert('操作失败'); });
|
|
});
|
|
|
|
// 退回
|
|
handleClick('.post-reject', function(id) {
|
|
var reason = prompt('请输入退回理由(必填):');
|
|
if (!reason || !reason.trim()) return;
|
|
api('/api/admin/posts/' + id + '/reject', 'POST', { reason: reason.trim() })
|
|
.then(function(d) { if (d.success) refreshPage(); else alert(d.message); })
|
|
.catch(function() { alert('操作失败'); });
|
|
});
|
|
|
|
// 锁定
|
|
handleClick('.post-lock', function(id) {
|
|
var reason = prompt('请输入锁定理由(必填):');
|
|
if (!reason || !reason.trim()) return;
|
|
api('/api/admin/posts/' + id + '/lock', 'POST', { reason: reason.trim() })
|
|
.then(function(d) { if (d.success) refreshPage(); else alert(d.message); })
|
|
.catch(function() { alert('操作失败'); });
|
|
});
|
|
|
|
// 解锁
|
|
handleClick('.post-unlock', function(id) {
|
|
api('/api/admin/posts/' + id + '/unlock', 'POST')
|
|
.then(function(d) { if (d.success) refreshPage(); else alert(d.message); })
|
|
.catch(function() { alert('操作失败'); });
|
|
});
|
|
})();
|