-
Notifications
You must be signed in to change notification settings - Fork 20
/
app.js
67 lines (66 loc) · 2 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
import polyfill from 'assets/plugins/polyfill'
import WxValidate from 'helpers/WxValidate'
import HttpResource from 'helpers/HttpResource'
import HttpService from 'helpers/HttpService'
import WxService from 'helpers/WxService'
import Tools from 'helpers/Tools'
import Config from 'config/config'
App({
onLaunch() {
console.log('onLaunch')
},
onShow() {
console.log('onShow')
},
onHide() {
console.log('onHide')
},
getUserInfo() {
if (this.globalData.userInfo) {
return this.globalData.userInfo;
} else {
return this.WxService.login().then(data => {
return this.WxService.getUserInfo();
}).then(data => {
this.globalData.userInfo = data.userInfo;
return this.globalData.userInfo;
})
}
},
globalData: {
userInfo: null,
tabBar:["/pages/error/index","/pages/error/index","/pages/error/index","/pages/error/index","/pages/error/index"]
},
navigateTo(url,param){
if (!url.startsWith("/pages/")){
url="/pages/"+url+"/index";
}
if (this.globalData.tabBar.indexOf(url) != -1) {
this.WxService.switchTab({
url: url
});
} else {
this.WxService.navigateTo(url, param);
}
},
renderUrl(url, defaultUrl) {
if (!url || url=="") {
url = defaultUrl;
}
if (url.indexOf("/pages/" + url) != 0) {
url = "/pages/" + url + "/index";
}
return url;
},
renderImage(path) {
if (!path) return ''
if (path.indexOf('http') !== -1) return path
return `${this.Config.fileBasePath}${path}`
},
WxValidate: (rules, messages) => new WxValidate(rules, messages),
HttpResource: (url, paramDefaults, actions, options) => new HttpResource(url, paramDefaults, actions, options).init(),
HttpService: new HttpService,
WxService: new WxService,
Tools: new Tools,
Config: Config,
})