refactor: 全局移除浏览器 alert 弹窗,统一使用页面内 showToast 通知

- 替换全部 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() 自定义确认弹窗(需用户确认的操作)
This commit is contained in:
2026-06-03 01:25:12 +08:00
parent 864a488ee0
commit 6c9a4414cb
11 changed files with 42 additions and 75 deletions

View File

@ -12,18 +12,6 @@
var isAuthor = btn.dataset.uid && btn.dataset.authorUid &&
btn.dataset.uid === btn.dataset.authorUid;
function showToast(msg) {
var toast = document.createElement('div');
toast.className = 'energize-toast';
toast.textContent = msg;
document.body.appendChild(toast);
setTimeout(function() { toast.classList.add('show'); }, 10);
setTimeout(function() {
toast.classList.remove('show');
setTimeout(function() { toast.remove(); }, 300);
}, 2000);
}
function showOverlay() {
overlay.style.display = 'flex';
}
@ -55,7 +43,7 @@
btn.addEventListener('click', function() {
if (isAuthor) {
showToast('无法给自己赋能');
showToast('无法给自己赋能', 'warning');
return;
}
btn.disabled = true;
@ -64,7 +52,7 @@
.then(function(d) {
btn.disabled = false;
if (!d.success || !d.data) {
showToast('获取状态失败,请稍后重试');
showToast('获取状态失败,请稍后重试', 'error');
return;
}
if (d.data.daily_exp_cap_reached) {
@ -72,7 +60,7 @@
}
var total = d.data.post_energize_total || 0;
if (total >= 20) {
showToast('对该文章赋能已达上限');
showToast('对该文章赋能已达上限', 'warning');
return;
}
if (total >= 10) {
@ -82,7 +70,7 @@
})
.catch(function() {
btn.disabled = false;
showToast('获取状态失败,请稍后重试');
showToast('获取状态失败,请稍后重试', 'error');
});
});
@ -106,16 +94,16 @@
.then(function(r) { return r.json(); })
.then(function(d) {
if (d.success) {
alert(d.data.message || '赋能成功!');
showToast(d.data && d.data.message ? d.data.message : '赋能成功!', 'success');
hideOverlay();
} else {
alert(d.message || '赋能失败');
showToast(d.message || '赋能失败', 'error');
lightBtn.disabled = false;
heavyBtn.disabled = false;
}
})
.catch(function() {
alert('请求失败');
showToast('请求失败', 'error');
lightBtn.disabled = false;
heavyBtn.disabled = false;
});