-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
97 lines (90 loc) · 2.31 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
//app.js
const Promise = require('bluebird.core.min.js');
App({
onLaunch: function () {
// 展示本地存储能力
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
var that = this;
// 获取用户信息
wx.getSetting({
success(res) {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称
wx.getUserInfo({
success(res) {
console.log(res.userInfo)
that.globalData.userInfo = res.userInfo;
}
})
}
}
})
wx.getSystemInfo({
success: function (res) {
that.globalData.windowWidth = res.windowWidth
that.globalData.windowHeight = res.windowHeight
}
});
},
login:function(){
let that = this;
// 登录
return new Promise(
function(resolve,reject){
wx.login({
success(res) {
if (res.code) {
// 发起网络请求
wx.request({
url: 'http://zhiduoshao.xyz:8888/api/login',
method: "POST",
data: {
code: res.code
},
success(response) {
// console.log(response.data)
resolve(response.data)
that.globalData.userID = response.data.userid;
}
})
// // 获取学习设置
// wx.request({
// url: 'http://zhiduoshao.xyz:8888/api/login', // 待定
// method: "GET",
// data: {
// code: res.code
// },
// success(response) {
// resolve(response.data)
// that.globalData.me = response.data.me
// }
// })
// console.log(res.code)
} else {
// console.log('登录失败!' + res.errMsg)
reject(response.errMsg)
}
}
})
})
},
globalData: {
userInfo: null,
userID: 0,
windowWidth: 0,
windowHeigth: 0,
/*
这些东西需要
*/
studyTime: 0, // 当日学习时长
me: {
setting: {
wordsOld: 15,
wordsTodo: 20,
}
},
rankIndex: 5,
}
})