-
Notifications
You must be signed in to change notification settings - Fork 472
/
Copy pathapp.js
121 lines (121 loc) · 3.11 KB
/
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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
var config = require('comm/script/config')
App({
globalData: {
userInfo: null
},
onLaunch: function() {
// 获取用户信息
this.getUserInfo()
//初始化缓存
this.initStorage()
},
getUserInfo:function(cb){
var that = this
wx.login({
success: function () {
wx.getUserInfo({
success: function (res) {
that.globalData.userInfo = res.userInfo
typeof cb == "function" && cb(that.globalData.userInfo)
}
})
}
})
},
getCity: function(cb) {
var that = this
wx.getLocation({
type: 'gcj02',
success: function (res) {
var locationParam = res.latitude + ',' + res.longitude + '1'
wx.request({
url: config.apiList.baiduMap,
data: {
ak: config.baiduAK,
location: locationParam,
output: 'json',
pois: '1'
},
method: 'GET',
success: function(res){
config.city = res.data.result.addressComponent.city.slice(0,-1)
typeof cb == "function" && cb(res.data.result.addressComponent.city.slice(0,-1))
},
fail: function(res) {
// 重新定位
that.getCity();
}
})
}
})
},
initStorage: function() {
wx.getStorageInfo({
success: function(res) {
// 判断电影收藏是否存在,没有则创建
if (!('film_favorite' in res.keys)) {
wx.setStorage({
key: 'film_favorite',
data: []
})
}
// 判断人物收藏是否存在,没有则创建
if (!('person_favorite' in res.keys)) {
wx.setStorage({
key: 'person_favorite',
data: []
})
}
// 判断电影浏览记录是否存在,没有则创建
if (!('film_history' in res.keys)) {
wx.setStorage({
key: 'film_history',
data: []
})
}
// 判断人物浏览记录是否存在,没有则创建
if (!('person_history' in res.keys)) {
wx.setStorage({
key: 'person_history',
data: []
})
}
// 个人信息默认数据
var personInfo = {
name: '',
nickName: '',
gender: '',
age: '',
birthday: '',
constellation: '',
company: '',
school: '',
tel: '',
email:'',
intro: ''
}
// 判断个人信息是否存在,没有则创建
if (!('person_info' in res.keys)) {
wx.setStorage({
key: 'person_info',
data: personInfo
})
}
// 判断相册数据是否存在,没有则创建
if (!('gallery' in res.keys)) {
wx.setStorage({
key: 'gallery',
data: []
})
}
// 判断背景卡选择数据是否存在,没有则创建
if (!('skin' in res.keys)) {
wx.setStorage({
key: 'skin',
data: ''
})
}
}
})
}
})