feat: display current weather and max temperature time in hero section

This commit is contained in:
2569718930@qq.com
2026-03-03 22:49:10 +08:00
parent 3cb53e6f9b
commit 7d3f497417
3 changed files with 50 additions and 2 deletions
+29 -2
View File
@@ -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 = `
<span>${weatherIcon} ${weatherText}</span>
`;
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(`<span>✈️ METAR ${cur.obs_time}${ageStr}</span>`);
}
if (cur.cloud_desc) parts.push(`<span>☁️ ${cur.cloud_desc}</span>`);
// Remove redundant cloud_desc here as it's now in main hero
if (cur.wx_desc && cur.wx_desc !== cur.cloud_desc) {
parts.push(`<span>🌦️ ${cur.wx_desc}</span>`);
}
if (cur.wind_speed_kt != null) {
parts.push(`<span>💨 ${cur.wind_speed_kt}kt</span>`);
}