-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathapp.js
More file actions
118 lines (104 loc) · 3.5 KB
/
app.js
File metadata and controls
118 lines (104 loc) · 3.5 KB
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
// app.js
import wxRequest from 'wechat-request';
import {
ApiConfig,
CommunityApi,
RelationApi,
ReservationTypeApi,
SuggestionTypeApi
} from './config/api';
function abc(){
console.log(abc)
}
App({
globalData: {},
getCommuntiies: function () {
wxRequest.get(CommunityApi.getCollection).then(response => {
wx.setStorage({key:'communities',data: response.data['hydra:member']});
})
},
getRelationWithHost: function(){
let hostParams = {
type: 'host'
}
wxRequest.get(RelationApi.getCollection,{params: hostParams}).then(response => {
wx.setStorage({key:'relationsWithHost',data: response.data['hydra:member']});
})
},
getRelationWithRoom: function(){
let hostParams = {
type: 'room'
}
wxRequest.get(RelationApi.getCollection,{params: hostParams}).then(response => {
wx.setStorage({key:'relationsWithRoom',data: response.data['hydra:member']});
})
},
getReservationTypes:function(){
wxRequest.get(ReservationTypeApi.getCollection).then(response=>{
wx.setStorage({key:'reservationTypes', data: response.data['hydra:member']});
});
},
getSuggestionTypes: function(){
wxRequest.get(SuggestionTypeApi.getCollection).then(response=>{
wx.setStorage({key:'suggestionTypes', data: response.data['hydra:member']});
});
},
onLaunch() {
//检查版本更新
const updateManager = wx.getUpdateManager()
updateManager.onUpdateReady(function () {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success(res) {
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate()
}
}
})
})
//wxRequest全局配置
wxRequest.defaults.baseURL = ApiConfig.apiHost;
wxRequest.defaults.headers.common.Accept = ApiConfig.accept + wxRequest.defaults.headers.common.Accept;
wxRequest.defaults.headers.get['Content-Type'] = ApiConfig.contentType;
wxRequest.defaults.headers.post['Content-Type'] = ApiConfig.contentType;
wxRequest.defaults.headers.put['Content-Type'] = ApiConfig.contentType;
wxRequest.defaults.headers.patch['Content-Type'] = ApiConfig.patchContentType;
//检查token是否过期
let expireAt = wx.getStorageSync('expireAt') * 1;
if(new Date() > new Date(expireAt)){
wx.removeStorage({key: 'authToken'});
wx.removeStorage({key: 'userInfo'});
wx.removeStorage({key: 'userId'});
wx.removeStorage({key: 'familyId'});
}
//如果已经登录,添加Authentication
wx.getStorage({
key: 'authToken',
success(res) {
wxRequest.defaults.headers['Authorization'] = 'Bearer ' + res.data;
}
})
//启动小程序时,获取常用信息,并设置到存储中
this.getCommuntiies();
this.getRelationWithHost();
this.getRelationWithRoom();
this.getReservationTypes();
this.getSuggestionTypes();
// 获取系统状态栏信息
// wx.getSystemInfo({
// success: e => {
// console.log(e);
// this.globalData.StatusBar = e.statusBarHeight;
// let capsule = wx.getMenuButtonBoundingClientRect();
// if (capsule) {
// this.globalData.Custom = capsule;
// this.globalData.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight;
// } else {
// this.globalData.CustomBar = e.statusBarHeight + 50;
// }
// }
// })
}
})