-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathapp.js
93 lines (88 loc) · 2.61 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
//app.js
const server = require('./services/server.js')
const util = require('./utils/util.js')
App({
onLaunch: function () {
this.login()
},
login: async function () {
try {
const resStatus = await server.request('GET', 'session/status')
const loginStatus = resStatus.data.status
if (loginStatus == 'wechat') {
// 已通过微信登陆
this.getUserInfo()
} else if (loginStatus == 'wechat_new') {
// 微信新用户,未设置信息
} else {
// 未登录,立刻登陆
const res = await util.as(wx.login)
// console.log(res.code)
// return
const resLogin = await server.request('POST', 'session/wechat', {
code: res.code
})
if (resLogin.statusCode == 200 && resLogin.data.new == false) {
this.getUserInfo()
}
}
} catch (err) {
console.log('登陆失败', err)
}
},
getUserInfo: async function () {
const resInfo = await server.request('GET', 'users/info/me')
this.globalData.userInfo = resInfo.data
this.globalData.hasUserInfo = true
return resInfo.data
},
editTabbar: function () {
let tabbar = this.globalData.tabBar;
let currentPages = getCurrentPages();
let _this = currentPages[currentPages.length - 1];
let pagePath = _this.route;
(pagePath.indexOf('/') != 0) && (pagePath = '/' + pagePath);
for (let i in tabbar.list) {
tabbar.list[i].selected = false;
(tabbar.list[i].pagePath == pagePath) && (tabbar.list[i].selected = true);
}
},
globalData: {
userInfo: {},
hasUserInfo: false,
tabBar: {
"list": [
{
"text": "首页",
"iconPath": "images/icons/home.png",
"selectedIconPath": "images/icons/home_selected.png",
"pagePath": "pages/index/index"
},
{
"text": "发布",
"iconPath": "images/icons/add.png",
"selectedIconPath": "images/icons/add_selected.png",
"pagePath": "pages/AddItem/AddItem"
},
{
"text": "消息",
"iconPath": "images/icons/message.png",
"selectedIconPath": "images/icons/message_selected.png",
"pagePath": "pages/Message/Message"
},
{
"text": "我的",
"iconPath": "images/icons/user.png",
"selectedIconPath": "images/icons/user_selected.png",
"pagePath": "pages/userInfo/userInfo"
}
],
"backgroundColor": "#fff",
"color": "#404969",
"selectedColor": "#ff7e67"
},
// 用于跳转草稿
status:'none',
taskID:''
}
})