From 5d8202311f84f2714d5e026bdfc00cff1ed3780e Mon Sep 17 00:00:00 2001 From: yarnom Date: Thu, 25 Sep 2025 13:07:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A38km=E4=B8=8B=E9=9B=A8?= =?UTF-8?q?=E9=A2=84=E8=AD=A6=E6=8A=A5=E8=AD=A6=E6=92=A4=E9=94=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/imdroid_radar.html | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/templates/imdroid_radar.html b/templates/imdroid_radar.html index d12bc8f..7ca5a4b 100644 --- a/templates/imdroid_radar.html +++ b/templates/imdroid_radar.html @@ -90,7 +90,13 @@ async function loadLatestTile(z, y, x) { const status = document.getElementById('tile_status'); const res = await fetch(`/api/radar/latest?z=${z}&y=${y}&x=${x}`); - if (!res.ok) { status.textContent = '未找到瓦片'; return; } + if (!res.ok) { + status.textContent = '未找到瓦片'; + // 当没有瓦片可用时,清空附近降雨提示,避免遗留旧提示 + const nb = document.getElementById('nearbyStatus'); + if (nb) { nb.textContent=''; nb.classList.remove('text-red-700'); nb.classList.add('text-gray-700'); } + return; + } const t = await res.json(); const fmt = (n, d=5)=> Number(n).toFixed(d); document.getElementById('tile_dt').textContent = t.dt; @@ -127,7 +133,13 @@ async function loadTileAt(z, y, x, dtStr) { const status = document.getElementById('tile_status'); const res = await fetch(`/api/radar/at?z=${z}&y=${y}&x=${x}&dt=${encodeURIComponent(dtStr)}`); - if (!res.ok) { status.textContent = '未找到瓦片'; return; } + if (!res.ok) { + status.textContent = '未找到瓦片'; + // 清空附近降雨提示,避免遗留 + const nb = document.getElementById('nearbyStatus'); + if (nb) { nb.textContent=''; nb.classList.remove('text-red-700'); nb.classList.add('text-gray-700'); } + return; + } const t = await res.json(); const fmt = (n, d=5)=> Number(n).toFixed(d); document.getElementById('tile_dt').textContent = t.dt; @@ -393,7 +405,13 @@ function maybeCalcNearbyRain(){ try{ const el = document.getElementById('nearbyStatus'); if(!el) return; - if(!gTileValues || !gXs || !gYs || gStLat===null || gStLon===null){ el.textContent=''; return; } + if(!gTileValues || !gXs || !gYs || gStLat===null || gStLon===null){ + // 数据不足时清空提示并恢复默认样式 + el.textContent=''; + el.classList.remove('text-red-700'); + el.classList.add('text-gray-700'); + return; + } const radiusM = 8000; // 8km const h=gTileValues.length, w=gTileValues[0].length; let hit=false, maxDBZ=null; @@ -405,7 +423,16 @@ if(dist <= radiusM){ hit=true; maxDBZ = maxDBZ==null?dbz:Math.max(maxDBZ, dbz); break; } } } - if(hit){ el.textContent = `附近8公里内检测到大于等于 40dBz 的雷达反射率,短时间内可能会下雨`; el.classList.remove('text-gray-700'); el.classList.add('text-red-700'); } + if(hit){ + el.textContent = `附近8公里内检测到大于等于 40dBz 的雷达反射率,短时间内可能会下雨`; + el.classList.remove('text-gray-700'); + el.classList.add('text-red-700'); + } else { + // 未命中时清空并恢复默认样式,避免提示“停留不消失” + el.textContent = ''; + el.classList.remove('text-red-700'); + el.classList.add('text-gray-700'); + } }catch(e){ /* ignore */ } }