Commit 12d23a93 by liangjianmin

feat(weather): 更新天气数据获取方式并添加天气图标

将天气数据获取的 API 更改为 wttr.in,并更新天气信息的显示方式。
添加天气图标以增强用户界面体验。
parent 836b7e0e
Showing with 6 additions and 3 deletions
...@@ -216,13 +216,15 @@ ...@@ -216,13 +216,15 @@
$("#current_year_3").text(year); $("#current_year_3").text(year);
$("#current_year_4").text(year); $("#current_year_4").text(year);
$.ajax({ $.ajax({
url: "http://wthrcdn.etouch.cn/weather_mini?city=深圳", url: "https://wttr.in/深圳?format=j1",
dataType: 'json', dataType: 'json',
type: "get", type: "get",
success: function (res) { success: function (res) {
$("#wendu").text(res.data.wendu + "℃"); var condition = res.current_condition[0];
$("#wendu").text(condition.temp_C + "℃");
var iconUrl = condition.weatherIconUrl[0].value;
$("#weatherIcon").attr("src", iconUrl).css("display", "inline-block");
} }
}) })
setInterval(function () { setInterval(function () {
var myDate = new Date; var myDate = new Date;
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
<span>北京时间&nbsp;&nbsp;</span> <span>北京时间&nbsp;&nbsp;</span>
<span class="color" id="time">00:00:00</span> <span class="color" id="time">00:00:00</span>
<span class="ml">深圳&nbsp;&nbsp;</span> <span class="ml">深圳&nbsp;&nbsp;</span>
<img id="weatherIcon" src="" alt="" style="width:20px;height:20px;vertical-align:middle;margin-right:4px;display:none;" />
<span class="color" id="wendu"></span> <span class="color" id="wendu"></span>
</p> </p>
<span class="title"></span> <span class="title"></span>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment