小程序缓存登录

// pages/my/index.js
const app = getApp()
Page({

_getuderinfo() {
let that = this
wx.getUserProfile({
desc: ‘获取用户信息’,
success(res) {
console.log(res)
let userInfo = res.userInfo
app.globalData.userInfo = userInfo
that.setData({
isShow: true,
userInfo
})
wx.setStorageSync(‘isShow’, true)
wx.setStorageSync(‘userInfo’, userInfo)
// 云开发 添加用户到数据库中
//检查 检查之前是否已经授权登陆,注册成功了
wx.cloud.database().collection(‘accounts’).add({
data:{
avatarUrl: userInfo.avatarUrl,
nickName: userInfo.nickName,
},
success(res){
console.log(res)
wx.showToast({
title: ‘登录成功’,
})
}
})
},
fail() {
wx.showToast({
title: ‘请求获取宁的信息’,
icon: ‘none’
})
}
})
},
data: {
// _getuderinfo: app._getuderinfo(),//调用公共appjs的方法
// yytest: app.yytest(),//调用公共appjs的方法
isShow: false,
userInfo: {

},
"sign":app.sign()

},

/**

  • 生命周期函数–监听页面加载
    */
    onShow (options) {
    let isShow = wx.getStorageSync(‘isShow’) || false
    let userInfo = wx.getStorageSync(‘userInfo’)
    if (isShow) {
    //已经授权过的
    this.setData({
    isShow: true,
    userInfo
    })
    }
    },

onShareAppMessage(){
return {
title: ‘新定义’,
path: ‘/pages/index/index’,
imageUrl:’/images/logo.png’
}
},
about() {
wx.showModal({
title: ‘关于’,
content: ‘定义内容yyeira’,
showCancel: false
})
}
})
/**

  • 生命周期函数–监听页面加载
    */
    onShow (options) {
    let isShow = wx.getStorageSync(‘isShow’) || false
    let userInfo = wx.getStorageSync(‘userInfo’)
    if (isShow) {
    //已经授权过的
    this.setData({
    isShow: true,
    userInfo
    })
    }
    },

猜你喜欢

转载自blog.csdn.net/weixin_43865875/article/details/122522479