fix: 赋能弹窗已满时不再弹出 + API 补上 post_energize_total 字段
- 赋能按钮点击时先查已赋能总量,>=20 直接 showToast 不弹窗 - 修复控制响应缺失 post_energize_total 字段导致前端永远走到 showOverlay - fetch 失败/.catch 改为 showToast 而非 showOverlay
This commit is contained in:
@ -103,6 +103,7 @@ func (ec *EnergyController) GetEnergyInfo(c *gin.Context) {
|
||||
"daily_energize_exp": info.DailyEnergizeExp,
|
||||
"daily_exp_cap": info.DailyExpCap,
|
||||
"daily_exp_cap_reached": info.DailyExpCapReached,
|
||||
"post_energize_total": info.PostEnergizeTotal,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -58,23 +58,32 @@
|
||||
showToast('无法给自己赋能');
|
||||
return;
|
||||
}
|
||||
btn.disabled = true;
|
||||
fetch('/api/energy/info?post_id=' + postId)
|
||||
.then(function(r) { return r.json(); })
|
||||
.then(function(d) {
|
||||
if (d.success && d.data) {
|
||||
btn.disabled = false;
|
||||
if (!d.success || !d.data) {
|
||||
showToast('获取状态失败,请稍后重试');
|
||||
return;
|
||||
}
|
||||
if (d.data.daily_exp_cap_reached) {
|
||||
capHint.style.display = 'block';
|
||||
}
|
||||
var total = d.data.post_energize_total || 0;
|
||||
if (total >= 20) {
|
||||
disableAll();
|
||||
} else if (total >= 10) {
|
||||
disableHeavy();
|
||||
showToast('对该文章赋能已达上限');
|
||||
return;
|
||||
}
|
||||
if (total >= 10) {
|
||||
disableHeavy();
|
||||
}
|
||||
showOverlay();
|
||||
})
|
||||
.catch(function() { showOverlay(); });
|
||||
.catch(function() {
|
||||
btn.disabled = false;
|
||||
showToast('获取状态失败,请稍后重试');
|
||||
});
|
||||
});
|
||||
|
||||
closeBtn.addEventListener('click', hideOverlay);
|
||||
|
||||
Reference in New Issue
Block a user