Initial Commit
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
// app.js
|
||||
App({
|
||||
onLaunch() {
|
||||
if (!wx.cloud) {
|
||||
console.error('请使用 2.2.3 或以上的基础库以使用云能力')
|
||||
} else {
|
||||
wx.cloud.init({
|
||||
traceUser: true
|
||||
})
|
||||
}
|
||||
|
||||
// 自动静默登录:调用云函数获取 openid
|
||||
this.silentLogin()
|
||||
},
|
||||
|
||||
silentLogin() {
|
||||
wx.cloud.callFunction({
|
||||
name: 'login',
|
||||
data: {},
|
||||
success: (res) => {
|
||||
const openid = res.result.openid
|
||||
const userInfo = res.result.userInfo || {}
|
||||
userInfo.openid = openid
|
||||
|
||||
this.globalData.userInfo = userInfo
|
||||
this.globalData.isLoggedIn = true
|
||||
wx.setStorageSync('userInfo', userInfo)
|
||||
|
||||
// 通知当前页面刷新
|
||||
if (this.loginReadyCallback) {
|
||||
this.loginReadyCallback(userInfo)
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('静默登录失败', err)
|
||||
this.globalData.isLoggedIn = false
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
globalData: {
|
||||
userInfo: null,
|
||||
isLoggedIn: false
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user