From 7d3f49741768cc9616afd403e6cfc9328244c88f Mon Sep 17 00:00:00 2001 From: "2569718930@qq.com" <2569718930@qq.com> Date: Tue, 3 Mar 2026 22:49:10 +0800 Subject: [PATCH] feat: display current weather and max temperature time in hero section --- web/static/app.js | 31 +++++++++++++++++++++++++++++-- web/static/index.html | 2 ++ web/static/style.css | 19 +++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/web/static/app.js b/web/static/app.js index 6b5bf13c..10bd1f7c 100644 --- a/web/static/app.js +++ b/web/static/app.js @@ -255,14 +255,38 @@ function renderHero(data) { const sym = data.temp_symbol || "°C"; const displayTemp = - cur.max_so_far != null && cur.max_so_far >= cur.temp + cur.max_so_far != null && cur.max_so_far >= (cur.temp || -999) ? cur.max_so_far : cur.temp; + // Use cloud_desc for the main weather indicator + const weatherText = cur.cloud_desc || cur.wx_desc || "未知"; + const weatherIcon = + { + 多云: "⛅", + 阴天: "☁️", + 少云: "🌤️", + 散云: "⛅", + 晴: "☀️", + }[cur.cloud_desc] || "🌡️"; + + document.getElementById("heroWeather").innerHTML = ` + ${weatherIcon} ${weatherText} + `; + document.getElementById("heroTemp").textContent = displayTemp != null ? displayTemp.toFixed(1) : "—"; document.getElementById("heroUnit").textContent = sym; + // Show if it's the peak recorded temperature + const isMax = cur.max_so_far != null && cur.max_so_far >= (cur.temp || -999); + const maxTimeEl = document.getElementById("heroMaxTime"); + if (isMax && cur.max_temp_time) { + maxTimeEl.textContent = `该城市今日最高温出现于当地时间 ${cur.max_temp_time}`; + } else { + maxTimeEl.textContent = ""; + } + document.getElementById("heroCurrent").textContent = cur.temp != null ? `${cur.temp}${sym} @${cur.obs_time || "—"}` : "—"; document.getElementById("heroWU").textContent = @@ -279,7 +303,10 @@ function renderHero(data) { } parts.push(`✈️ METAR ${cur.obs_time}${ageStr}`); } - if (cur.cloud_desc) parts.push(`☁️ ${cur.cloud_desc}`); + // Remove redundant cloud_desc here as it's now in main hero + if (cur.wx_desc && cur.wx_desc !== cur.cloud_desc) { + parts.push(`🌦️ ${cur.wx_desc}`); + } if (cur.wind_speed_kt != null) { parts.push(`💨 ${cur.wind_speed_kt}kt`); } diff --git a/web/static/index.html b/web/static/index.html index c8252e85..ebe2679f 100644 --- a/web/static/index.html +++ b/web/static/index.html @@ -65,10 +65,12 @@