fix: 赋能弹窗已满时不再弹出 + API 补上 post_energize_total 字段

- 赋能按钮点击时先查已赋能总量,>=20 直接 showToast 不弹窗
- 修复控制响应缺失 post_energize_total 字段导致前端永远走到 showOverlay
- fetch 失败/.catch 改为 showToast 而非 showOverlay
This commit is contained in:
2026-06-03 00:23:35 +08:00
parent 1af9fba291
commit 2d05da6709
2 changed files with 21 additions and 11 deletions

View File

@ -103,6 +103,7 @@ func (ec *EnergyController) GetEnergyInfo(c *gin.Context) {
"daily_energize_exp": info.DailyEnergizeExp, "daily_energize_exp": info.DailyEnergizeExp,
"daily_exp_cap": info.DailyExpCap, "daily_exp_cap": info.DailyExpCap,
"daily_exp_cap_reached": info.DailyExpCapReached, "daily_exp_cap_reached": info.DailyExpCapReached,
"post_energize_total": info.PostEnergizeTotal,
}) })
} }

View File

@ -58,23 +58,32 @@
showToast('无法给自己赋能'); showToast('无法给自己赋能');
return; return;
} }
btn.disabled = true;
fetch('/api/energy/info?post_id=' + postId) fetch('/api/energy/info?post_id=' + postId)
.then(function(r) { return r.json(); }) .then(function(r) { return r.json(); })
.then(function(d) { .then(function(d) {
if (d.success && d.data) { btn.disabled = false;
if (d.data.daily_exp_cap_reached) { if (!d.success || !d.data) {
capHint.style.display = 'block'; showToast('获取状态失败,请稍后重试');
} return;
var total = d.data.post_energize_total || 0; }
if (total >= 20) { if (d.data.daily_exp_cap_reached) {
disableAll(); capHint.style.display = 'block';
} else if (total >= 10) { }
disableHeavy(); var total = d.data.post_energize_total || 0;
} if (total >= 20) {
showToast('对该文章赋能已达上限');
return;
}
if (total >= 10) {
disableHeavy();
} }
showOverlay(); showOverlay();
}) })
.catch(function() { showOverlay(); }); .catch(function() {
btn.disabled = false;
showToast('获取状态失败,请稍后重试');
});
}); });
closeBtn.addEventListener('click', hideOverlay); closeBtn.addEventListener('click', hideOverlay);