- 替换全部 11 个文件中 36 处 alert() 为 showToast() - API 错误/异常使用 showToast(msg, 'error'),3秒自动消失 - 表单校验提示使用 showToast(msg, 'warning'),3秒自动消失 - 成功确认使用 showToast(msg, 'success'),3秒自动消失 - 移除 post-energize.js 中与全局 showToast 冲突的本地实现 - 删除 posts.css 中已失去引用的 .energize-toast 样式 - 保留 showConfirm() 自定义确认弹窗(需用户确认的操作)
56 lines
2.4 KiB
JavaScript
56 lines
2.4 KiB
JavaScript
(function() {
|
|
// CSRF token 由 shared/utils.js 的 getCSRFToken() 统一提供
|
|
// showConfirm / showPrompt / escapeHtml 由 shared/utils.js 统一提供
|
|
// api 对象 (api.get/api.post/api.put) 由 admin/common.js 统一提供
|
|
|
|
function refreshPage() { window.location.reload(); }
|
|
|
|
function handleClick(sel, confirmMsg, actionFn) {
|
|
var btns = document.querySelectorAll(sel);
|
|
btns.forEach(function(btn) {
|
|
btn.addEventListener('click', async function() {
|
|
var id = btn.getAttribute('data-id');
|
|
if (confirmMsg) {
|
|
var ok = await showConfirm('确认', confirmMsg);
|
|
if (!ok) return;
|
|
}
|
|
actionFn(id);
|
|
});
|
|
});
|
|
}
|
|
|
|
// 审核通过
|
|
handleClick('.post-approve', '确定审核通过此文章吗?', function(id) {
|
|
api.post('/api/admin/posts/' + id + '/approve')
|
|
.then(function(d) { if (d.success) refreshPage(); else showToast(d.message || '操作失败', 'error'); })
|
|
.catch(function() { showToast('操作失败', 'error'); });
|
|
});
|
|
|
|
// 退回
|
|
handleClick('.post-reject', null, function(id) {
|
|
showPrompt('请输入退回理由(必填):').then(function(reason) {
|
|
if (!reason || !reason.trim()) return;
|
|
api.post('/api/admin/posts/' + id + '/reject', { reason: reason.trim() })
|
|
.then(function(d) { if (d.success) refreshPage(); else showToast(d.message || '操作失败', 'error'); })
|
|
.catch(function() { showToast('操作失败', 'error'); });
|
|
});
|
|
});
|
|
|
|
// 锁定
|
|
handleClick('.post-lock', null, function(id) {
|
|
showPrompt('请输入锁定理由(必填):').then(function(reason) {
|
|
if (!reason || !reason.trim()) return;
|
|
api.post('/api/admin/posts/' + id + '/lock', { reason: reason.trim() })
|
|
.then(function(d) { if (d.success) refreshPage(); else showToast(d.message || '操作失败', 'error'); })
|
|
.catch(function() { showToast('操作失败', 'error'); });
|
|
});
|
|
});
|
|
|
|
// 解锁
|
|
handleClick('.post-unlock', '确定解锁此文章吗?', function(id) {
|
|
api.post('/api/admin/posts/' + id + '/unlock')
|
|
.then(function(d) { if (d.success) refreshPage(); else showToast(d.message || '操作失败', 'error'); })
|
|
.catch(function() { showToast('操作失败', 'error'); });
|
|
});
|
|
})();
|