-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
63 lines (56 loc) · 1.37 KB
/
Copy pathapp.js
File metadata and controls
63 lines (56 loc) · 1.37 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
//app.js
App({
onLaunch: function () {
let that = this
// 引入 BaaS SDK
require('./utils/sdk-v1.3.0')
let clientId = this.globalData.clientId
wx.BaaS.init(clientId)
// 打开调试
wx.setEnableDebug({
enableDebug: true
})
// 微信用户登录小程序,获取用户ID
wx.BaaS.login(false).then(res => {
// 登录成功
try {
wx.setStorageSync('id', res.id)
let MyUser = new wx.BaaS.User()
let userID = res.id
MyUser.get(userID).then(res => {
// success
// 缓存收藏
let starArr = res.data.star;
let starObj = {}
for (let i = 0; i < starArr.length; i++) {
starObj[starArr[i]] = true
}
wx.setStorage({
key: "star",
data: starObj
})
}, err => {
// err
console.log(res)
})
} catch (e) {
console.log(e)
}
}, res => {
// 登录失败
console.log(res)
})
},
onHide: function(){
wx.removeStorage({
key: 'isOnAccelerometer',
success: function (res) {
console.log(res.data)
}
})
},
globalData: {
clientId: '20a34091b2d4e40fa865', // 从 BaaS 后台获取 ClientID
tableId: '35340', // 从 https://cloud.minapp.com/dashboard/ 管理后台的数据表中获取
}
})