From 2d05da67094ed4a9a6b78599391d97d56d986cc8 Mon Sep 17 00:00:00 2001 From: Victor_Jay Date: Wed, 3 Jun 2026 00:23:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B5=8B=E8=83=BD=E5=BC=B9=E7=AA=97?= =?UTF-8?q?=E5=B7=B2=E6=BB=A1=E6=97=B6=E4=B8=8D=E5=86=8D=E5=BC=B9=E5=87=BA?= =?UTF-8?q?=20+=20API=20=E8=A1=A5=E4=B8=8A=20post=5Fenergize=5Ftotal=20?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 赋能按钮点击时先查已赋能总量,>=20 直接 showToast 不弹窗 - 修复控制响应缺失 post_energize_total 字段导致前端永远走到 showOverlay - fetch 失败/.catch 改为 showToast 而非 showOverlay --- internal/controller/energy_controller.go | 1 + .../MetaLab-2026/static/js/post-energize.js | 31 ++++++++++++------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/internal/controller/energy_controller.go b/internal/controller/energy_controller.go index 2bbb474..13aaf29 100644 --- a/internal/controller/energy_controller.go +++ b/internal/controller/energy_controller.go @@ -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, }) } diff --git a/templates/MetaLab-2026/static/js/post-energize.js b/templates/MetaLab-2026/static/js/post-energize.js index 7135d92..2cf37f6 100644 --- a/templates/MetaLab-2026/static/js/post-energize.js +++ b/templates/MetaLab-2026/static/js/post-energize.js @@ -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) { - 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(); - } + 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) { + showToast('对该文章赋能已达上限'); + return; + } + if (total >= 10) { + disableHeavy(); } showOverlay(); }) - .catch(function() { showOverlay(); }); + .catch(function() { + btn.disabled = false; + showToast('获取状态失败,请稍后重试'); + }); }); closeBtn.addEventListener('click', hideOverlay);