feat: prompt/confirm 替换为自定义弹窗
- shared/utils.js 新增 showConfirm()/showPrompt() 通用函数(inline CSS,无需额外样式) - admin/common.js 移除重复 showConfirm(),统一使用 utils.js - admin/posts.js: 3 处 confirm/prompt 替换(审核/退回/锁定) - admin/comments.js: 1 处 confirm 替换 - settings/index.html: 4 处 confirm + 1 处 prompt 替换 - studio/posts.html + drafts.html: 3 处 confirm 替换 - post-view.js + login.js + post-favorite.js: 3 处 confirm 替换
This commit is contained in:
@ -1,48 +1,53 @@
|
||||
(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, actionFn) {
|
||||
function handleClick(sel, confirmMsg, actionFn) {
|
||||
var btns = document.querySelectorAll(sel);
|
||||
btns.forEach(function(btn) {
|
||||
btn.addEventListener('click', function() {
|
||||
btn.addEventListener('click', async function() {
|
||||
var id = btn.getAttribute('data-id');
|
||||
if (confirm('确定执行此操作吗?')) {
|
||||
actionFn(id);
|
||||
if (confirmMsg) {
|
||||
var ok = await showConfirm('确认', confirmMsg);
|
||||
if (!ok) return;
|
||||
}
|
||||
actionFn(id);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 审核通过
|
||||
handleClick('.post-approve', function(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-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 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-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 alert(d.message); })
|
||||
.catch(function() { alert('操作失败'); });
|
||||
});
|
||||
});
|
||||
|
||||
// 解锁
|
||||
handleClick('.post-unlock', function(id) {
|
||||
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('操作失败'); });
|
||||
|
||||
Reference in New Issue
Block a user