-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
201 lines (198 loc) · 8.1 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
var http = require('utils/http.js');
var QQMapWX = require('libs/qqmap-wx-jssdk.js');
App({
data:{
userInfo:'',
token:'',
oAddress :'',
},
globalData:{
mobile:''
},
onShareAppMessage: function () {
return {
title: '华腾智能停车',
path: '/pages/index/index',
}
},
onLaunch: function (){
const updateManager = wx.getUpdateManager()
console.log(updateManager)
updateManager.onCheckForUpdate(function (res) {
// 请求完新版本信息的回调
console.log(res.hasUpdate)
})
updateManager.onUpdateReady(function () {
// wx.showModal({
// title: '更新提示',
// content: '新版本已经准备好,请下载并重启应用?',
// showCancel: false,
// success: function (res) {
// if (res.confirm) {
// // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
// updateManager.applyUpdate()
// }
// }
// })
updateManager.applyUpdate()
})
updateManager.onUpdateFailed(function () {
// 新的版本下载失败
wx.showModal({
title: '更新提示',
content: '新版本下载失败',
showCancel: false
})
})
var that = this;
wx.showLoading({
title: '登录中...'
});
wx.getLocation({
type: 'wgs84', //返回可以用于wx.openLocation的经纬度
success: function (res) {
var latitude = res.latitude;
var longitude = res.longitude;
// 实例化API核心类
var demo = new QQMapWX({
key: 'XKBBZ-5RKWS-4TQOB-6CMPO-U2ORF-V5BKW' // 必填
});
demo.reverseGeocoder({
location: {
latitude: latitude,
longitude: longitude
},
success: function (res) {
// 获取用户当前所在区域
var oAddress = res.result.address_component.district;
wx.setStorage({
key: 'oAddress',
data: oAddress
});
wx.login({
success: function (res) {
wx.request({
url: http.reqUrl + '/xiaoLogin',
data: {
code: res.code,
areaName: oAddress
},
method: 'POST',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success: function (res) {
console.log(res)
if(res.data.success){
wx.hideLoading();
wx.setStorage({
key: 'token',
data: res.data.data.token,
complete: function () {
}
})
wx.setStorage({
key: 'session_key',
data: res.data.data.session_key,
complete: function () {
}
})
wx.setStorage({
key: 'mobile',
data: res.data.data.mobile,
complete: function () {}
})
that.globalData.mobile = res.data.data.mobile
let num = res.data.data.mobile
if (that.employIdCallback) {
that.employIdCallback(num);
}
}
if(res.data.fail){
wx.hideLoading();
wx.showModal({
title: '提示',
content: '登录异常,请稍后重试',
showCancel: false,
success: function (res) {
if (res.confirm) {
}
}
});
}
},
fail: function (res) {
wx.hideLoading();
wx.showModal({
title: '提示',
content: '微信登录出错,请重新进入小程序或清除下缓存!',
showCancel: false,
success: function (res) {
if (res.confirm) {
}
}
});
}
});
}
});
}
});
}
});
wx.checkSession({
success: function () {
//session 未过期,并且在本生命周期一直有效
},
fail: function () {
//登录态过期
wx.login() //重新登录
}
})
},
onLoad:function(){
},
getUserInfo: function (cb) {
var that = this;
if (this.globalData.userInfo) {
// 用户信息
if (!this.globalData.userInfo.ofoInfo) {
var userInfo2 = wx.getStorageSync("userInfo");
if (userInfo2 && userInfo2 == 'object')
this.globalData.userInfo = userInfo2;
}
typeof cb == "function" && cb(this.globalData.userInfo)
return;
}
var userInfo2 = wx.getStorageSync("userInfo");
if (userInfo2 && typeof userInfo2 == 'object') {
this.globalData.userInfo = userInfo2
typeof cb == "function" && cb(this.globalData.userInfo)
return
}
//调用登录接口
wx.login({
success: function () {
wx.getUserInfo({
success: function (res) {
that.globalData.userInfo = res.userInfo
typeof cb == "function" && cb(that.globalData.userInfo)
wx.setStorage({
key: 'userInfo',
data: res.userInfo
});
}
})
}
})
},
getUserInfoSync() {
return this.globalData.userInfo;
},
globalData: {
userInfo: null
},
func: {
req: http.req
}
})