- Post 模型新增 LockReason 字段,锁定必填理由,解锁清空 - PostLockRequest DTO:reason 必填,1-500字 - Admin JS:锁定操作弹出 prompt 要求填写理由 - 编辑器锁定横幅显示"锁定理由:XXX",理由为空时不显示该行
64 lines
2.3 KiB
JavaScript
64 lines
2.3 KiB
JavaScript
(function() {
|
|
function getCSRFToken() {
|
|
var meta = document.querySelector('meta[name="csrf-token"]');
|
|
return meta ? meta.getAttribute('content') : '';
|
|
}
|
|
|
|
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('操作失败'); });
|
|
});
|
|
})();
|