From 8809459f1b46166ea3463b9358784b09b14ba585 Mon Sep 17 00:00:00 2001 From: snowy Date: Mon, 29 Apr 2024 16:58:52 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=20=E8=BD=BB=E9=9B=AA=E5=A4=A9=E6=B0=94?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E7=A9=BAaqi=E5=80=BC=E7=9A=84=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + liteyuki/plugins/liteyuki_weather/qw_api.py | 1 + .../resources/liteyuki_weather/lang/en.lang | 3 ++- .../resources/liteyuki_weather/lang/ja.lang | 3 ++- .../liteyuki_weather/lang/zh-CN.lang | 3 ++- .../templates/js/weather_now.js | 24 ++++++++++++------- .../vanilla_resource/templates/js/status.js | 6 ++--- 7 files changed, 26 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 15321456..7298af6d 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ liteyuki/resources/templates/latest-debug.html pyproject.toml test.py +line_count.py # nuitka main.build/ diff --git a/liteyuki/plugins/liteyuki_weather/qw_api.py b/liteyuki/plugins/liteyuki_weather/qw_api.py index ebe334a6..ed95813b 100644 --- a/liteyuki/plugins/liteyuki_weather/qw_api.py +++ b/liteyuki/plugins/liteyuki_weather/qw_api.py @@ -52,6 +52,7 @@ def get_local_data(ulang_code: str) -> dict: "tomorrow" : ulang.get("weather.tomorrow"), "day" : ulang.get("weather.day"), "night" : ulang.get("weather.night"), + "no_aqi" : ulang.get("weather.no_aqi"), } diff --git a/liteyuki/resources/liteyuki_weather/lang/en.lang b/liteyuki/resources/liteyuki_weather/lang/en.lang index b7fa8564..9822bda7 100644 --- a/liteyuki/resources/liteyuki_weather/lang/en.lang +++ b/liteyuki/resources/liteyuki_weather/lang/en.lang @@ -8,4 +8,5 @@ weather.sunday=Sun weather.day=Day weather.night=Night weather.today=Today -weather.tomorrow=Tomorrow \ No newline at end of file +weather.tomorrow=Tomorrow +weather.no_aqi=No AQI data \ No newline at end of file diff --git a/liteyuki/resources/liteyuki_weather/lang/ja.lang b/liteyuki/resources/liteyuki_weather/lang/ja.lang index 56845377..58bcd04e 100644 --- a/liteyuki/resources/liteyuki_weather/lang/ja.lang +++ b/liteyuki/resources/liteyuki_weather/lang/ja.lang @@ -8,4 +8,5 @@ weather.sunday=日 weather.day=昼 weather.night=夜 weather.today=今日 -weather.tomorrow=明日 \ No newline at end of file +weather.tomorrow=明日 +weather.no_aqi=空気質データなし \ No newline at end of file diff --git a/liteyuki/resources/liteyuki_weather/lang/zh-CN.lang b/liteyuki/resources/liteyuki_weather/lang/zh-CN.lang index e2c8cd77..a4f44d58 100644 --- a/liteyuki/resources/liteyuki_weather/lang/zh-CN.lang +++ b/liteyuki/resources/liteyuki_weather/lang/zh-CN.lang @@ -8,4 +8,5 @@ weather.sunday=周日 weather.day=白天 weather.night=夜晚 weather.today=今天 -weather.tomorrow=明天 \ No newline at end of file +weather.tomorrow=明天 +weather.no_aqi=暂无AQI数据 \ No newline at end of file diff --git a/liteyuki/resources/liteyuki_weather/templates/js/weather_now.js b/liteyuki/resources/liteyuki_weather/templates/js/weather_now.js index aafdd91c..55e7057b 100644 --- a/liteyuki/resources/liteyuki_weather/templates/js/weather_now.js +++ b/liteyuki/resources/liteyuki_weather/templates/js/weather_now.js @@ -28,15 +28,21 @@ let locationData = data["location"] // 处理aqi let aqiValue = 0 -aqi["aqi"].forEach( - (item) => { - if (item["defaultLocalAqi"]) { - document.getElementById("aqi-data").innerText = "AQI " + item["valueDisplay"] + " " + item["category"] - // 将(255,255,255)这种格式的颜色设置给css - document.getElementById("aqi-dot").style.backgroundColor = "rgb(" + item["color"] + ")" +if ("aqi" in aqi) { + aqi["aqi"].forEach( + (item) => { + if (item["defaultLocalAqi"]) { + document.getElementById("aqi-data").innerText = "AQI " + item["valueDisplay"] + " " + item["category"] + // 将(255,255,255)这种格式的颜色设置给css + document.getElementById("aqi-dot").style.backgroundColor = "rgb(" + item["color"] + ")" + } } - } -) + ) +} else { + document.getElementById("aqi-dot").style.backgroundColor = '#fff' + document.getElementById("aqi-data").innerText = localData['no_aqi'] +} + templates = { "time": weatherNow["now"]["obsTime"], @@ -92,7 +98,7 @@ weatherDaily['daily'].forEach( return } let today = days[index] - if (index >= 2){ + if (index >= 2) { today += `(${item["fxDate"].split("-")[1]}.${item["fxDate"].split("-")[2]})` } let dailyItemDiv = document.importNode(document.getElementById("daily-item-template").content, true) diff --git a/liteyuki/resources/vanilla_resource/templates/js/status.js b/liteyuki/resources/vanilla_resource/templates/js/status.js index 4930016c..2ae11a88 100644 --- a/liteyuki/resources/vanilla_resource/templates/js/status.js +++ b/liteyuki/resources/vanilla_resource/templates/js/status.js @@ -289,9 +289,9 @@ function main() { let mottoFrom = `${motto['author']} ${motto['source']}` document.getElementById('motto-text').innerText = mottoText document.getElementById('motto-from').innerText = mottoFrom - - document.getElementById('author-description').innerText = localData['description'] + ' Powered by Liteyuki' - + let text = document.createElement('div') + text.innerText = localData['description'] + ' Powered by Liteyuki' + document.getElementById('author-description').appendChild(text) }