-
Notifications
You must be signed in to change notification settings - Fork 0
/
weather.js
74 lines (72 loc) · 1.95 KB
/
weather.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
(function(window) {
var ws = "日一二三四五六";
var document = window.document;
var $ = (sel => document.querySelector(sel));
var sn = "";
var timer = null;
var nativeInfoData = {};
//请求天气接口
window.getTemperature = function() {
return fetch(`https://cloud-rest.lenovomm.com/cloud-weather/weather/localWeather`, {
headers: {
"Accept": "application/json",
},
})
.then(response => {
// console.log(response);
return response.json();
})
.then(res => {
// console.log(res);
if (res.code == 10000 && res.data.length) {
this.setWeatherLogic(res.data[0])
}
})
}
this.getTemperature();
//设置时间
setInterval(function() {
var now = new Date();
var yea = now.getFullYear();
var mon = now.getMonth() + 1;
var day = now.getDate();
var hou = now.getHours();
var min = now.getMinutes();
var wee = now.getDay();
var wz = ws[wee];
$('.info')
.style.opacity = '1';
}, 1000);
window.setWeatherLogic = function(obj) {
let {
weatherIndex
} = obj.current;
let {
temperature_am,
temperature_pm
} = obj.forecast;
if (weatherIndex) {
$('#weather-icon')
.style.display = 'block';
$('#weather-icon')
.setAttribute('src', `weather / $ {
weatherIndex
}.svg`); /*这里可能要修改一下*/
}
let temperature_interval = '';
if (!temperature_pm || !temperature_am) return;
temperature_interval = Number(temperature_pm) > Number(temperature_am) ? `$ {
temperature_am
}~$ {
temperature_pm
}℃` : `$ {
temperature_pm
}~$ {
temperature_am
}℃`;
$('.temp')
.style.display = 'block';
$('.temp')
.innerText = temperature_interval;
}
})(window)