From d46fe85c705eea01db08d42334d38269c125a346 Mon Sep 17 00:00:00 2001 From: lkddi Date: Sat, 25 Apr 2026 12:04:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=87=AA=E5=8A=A8=E9=92=93?= =?UTF-8?q?=E9=B1=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../partials/games/fishing-panel.blade.php | 74 ++++++++++++++++++- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/resources/views/chat/partials/games/fishing-panel.blade.php b/resources/views/chat/partials/games/fishing-panel.blade.php index ba67015..8051c1b 100644 --- a/resources/views/chat/partials/games/fishing-panel.blade.php +++ b/resources/views/chat/partials/games/fishing-panel.blade.php @@ -450,11 +450,81 @@ _autoFishCdCountdown = null; } const btn = document.getElementById('fishing-btn'); - btn.textContent = '🎣 钓鱼'; - btn.disabled = false; + if (btn) { + btn.textContent = '🎣 钓鱼'; + btn.disabled = false; + } fishingTimer = null; fishingReelTimeout = null; removeBobber(); } + /** + * 检查并自动开启钓鱼 + */ + function checkAndAutoStartFishing() { + @if(auth()->check()) + @php + $autoFishingMinutesLeft = app(\App\Services\ShopService::class)->getActiveAutoFishingMinutesLeft(auth()->user()); + $cdKey = "fishing:cd:" . auth()->id(); + $cooldown = \Illuminate\Support\Facades\Redis::ttl($cdKey); + $cooldown = $cooldown > 0 ? $cooldown : 0; + @endphp + const minutesLeft = {{ $autoFishingMinutesLeft }}; + const initialCooldown = {{ $cooldown }}; + + if (minutesLeft > 0 && !_autoFishing) { + _autoFishing = true; + + if (initialCooldown > 0) { + // 如果还在冷却中,恢复冷却倒计时和停止按钮 + console.log(`检测到自动钓鱼卡有效,恢复钓鱼状态,剩余冷却 ${initialCooldown}s`); + const btn = document.getElementById('fishing-btn'); + if (btn) { + btn.disabled = true; + btn.textContent = `⏳ 冷却 ${initialCooldown}s`; + btn.onclick = null; + } + + _showAutoFishStopBtn(initialCooldown); + + let remaining = initialCooldown; + _autoFishCdCountdown = setInterval(() => { + remaining--; + const b = document.getElementById('fishing-btn'); + if (b) b.textContent = `⏳ 冷却 ${remaining}s`; + if (remaining <= 0) { + clearInterval(_autoFishCdCountdown); + _autoFishCdCountdown = null; + } + }, 1000); + + _autoFishCdTimer = setTimeout(() => { + _autoFishCdTimer = null; + _hideAutoFishStopBtn(); + if (_autoFishing) startFishing(); + }, initialCooldown * 1000); + } else { + // 无冷却,直接开始 + console.log('检测到自动钓鱼卡有效,自动抛竿'); + startFishing(); + } + } + @endif + } + + document.addEventListener('DOMContentLoaded', () => { + // 页面初始化时检查 + checkAndAutoStartFishing(); + + // 监听全员清屏事件(清屏后由于 DOM 可能会导致部分提示被清,确保自动钓鱼能继续,不过由于上面已是闭环,这里只是做个保险调用) + // 主要是如果用户在开着自动钓鱼,清屏不会终止 JS 变量,所以不需要完全重置。 + // 但如果要求“全员清屏后也能自动开启”(指可能因为某种原因刷新了聊天流),我们可以额外保障一下。 + window.addEventListener('chat:screen-cleared', () => { + if (!_autoFishing) { + checkAndAutoStartFishing(); + } + }); + }); +