forked from tabalt/WeatherHelper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (39 loc) · 1017 Bytes
/
app.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
//app.js
var api = require('./libs/api')
App({
onLaunch: function() {
//加载天气数据
this.loadWeatherData();
// 获取用户信息
this.getUserInfo();
//...
},
loadWeatherData: function() {
var citySelected = wx.getStorageSync('citySelected') || [];
if (citySelected.length == 0) {
citySelected.unshift("__location__");
wx.setStorageSync('citySelected', citySelected);
}
var that = this
for (var idx in citySelected) {
var cityCode = citySelected[idx];
api.loadWeatherData(cityCode, function (cityCode, data) {
var weatherData = wx.getStorageSync('weatherData') || {};
weatherData[cityCode] = data;
wx.setStorageSync('weatherData', weatherData);
});
}
},
getUserInfo: function() {
var that = this
wx.getUserInfo({
withCredentials: false,
success: function (res) {
that.globalData.userInfo = res.userInfo
}
})
},
globalData: {
userInfo: null
}
})