Files
mce/templates/admin/static/js/posts.js
Victor_Jay a8a52f5fd0 refactor: 提取公共工具函数到 shared/utils.js,消除 DRY 重复
- escapeHtml 8 处定义合并为 shared/utils.js 1 处:删除 shortcode.js、posts/show.html、settings/index.html、comments.js、energy.js、common.js 中的重复定义
- formatTime 6 处定义合并为 1 处:统一 ISO 时间格式化逻辑
- api() 5 处定义收敛:前台页面使用 shared/utils.js 统一 api(method,url,data),admin 使用 common.js 的 api 对象
- showToast 3 处定义合并为 1 处:自包含内联样式,前后台通用
- admin/posts.js api 调用迁移为 api.post()
2026-06-02 19:50:52 +08:00

51 lines
1.9 KiB
JavaScript

(function() {
// CSRF token 由 shared/utils.js 的 getCSRFToken() 统一提供
// api 对象 (api.get/api.post/api.put) 由 admin/common.js 统一提供
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.post('/api/admin/posts/' + id + '/approve')
.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.post('/api/admin/posts/' + id + '/reject', { 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.post('/api/admin/posts/' + id + '/lock', { reason: reason.trim() })
.then(function(d) { if (d.success) refreshPage(); else alert(d.message); })
.catch(function() { alert('操作失败'); });
});
// 解锁
handleClick('.post-unlock', function(id) {
api.post('/api/admin/posts/' + id + '/unlock')
.then(function(d) { if (d.success) refreshPage(); else alert(d.message); })
.catch(function() { alert('操作失败'); });
});
})();