You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.1 KiB
55 lines
1.1 KiB
// pages/login/login.js
|
|
Page({
|
|
data:{
|
|
userInfo:'',
|
|
avatarUrl:'',
|
|
nickName:''
|
|
},
|
|
onLoad(){
|
|
/*
|
|
let user=wx.getStorageSync('user')
|
|
this.setData({
|
|
userInfo:user
|
|
})
|
|
wx.switchTab({
|
|
url: '/pages/index/index'
|
|
})
|
|
*/
|
|
},
|
|
login(){
|
|
let that = this;
|
|
console.log('点击事件执行了')
|
|
wx.getUserProfile({
|
|
desc: '必须授权才能使用',
|
|
success:res=>{
|
|
let user=res.userInfo
|
|
let avatarUrl=res.userInfo.avatarUrl
|
|
let nickName=res.userInfo.nickName
|
|
|
|
wx.setStorageSync('user', user)
|
|
wx.setStorageSync('avatarUrl', avatarUrl)
|
|
wx.setStorageSync('nickName', nickName)
|
|
console.log('成功',res)
|
|
wx.cloud.database().collection('user').add({
|
|
data: {
|
|
userInfo:user,
|
|
avatarUrl:user.avatarUrl,
|
|
nickName:user.nickName
|
|
}
|
|
})
|
|
},
|
|
fall:res=>{
|
|
console.log('失败',res)
|
|
}
|
|
})
|
|
wx.switchTab({
|
|
url: '/pages/index/index'
|
|
})
|
|
},
|
|
nologin(){
|
|
this.setData({
|
|
userInfo:''
|
|
})
|
|
wx.setStorageSync('user', null)
|
|
},
|
|
}) |