Commit dc94002c by liangyuhang

用户登录退出

parent 219f1d76
{ {
"usingComponents": {} "usingComponents": {
"reportList": "/components/reportList/reportList"
}
} }
\ No newline at end of file
// pages/crisisrep/crisisrep.js // pages/usercenter/usercenter.js
const app = getApp()
var http = require('../../utils/http')
Page({ Page({
/** /**
* 页面的初始数据 * 页面的初始数据
*/ */
data: { data: {
isLogin:wx.getStorageSync('isLogin'),
userName:wx.getStorageSync('userName'),
headUrl:wx.getStorageSync('headUrl'),
roleId:wx.getStorageSync('roleId')
},
// onGetPhoneNumber(e){
// console.log(e);
// console.log("encryptedData:"+e.detail.encryptedData);
// console.log("iv:"+e.detail.iv);
// },
onGetPhoneNumber(e){
wx.showLoading({
title: '正在登录...'
})
if (e.detail.iv) {
wx.login({
success: res => {
// console.log(res)
let data = {
encryptedData: e.detail.encryptedData,
iv: e.detail.iv,
code: res.code
}
http.postRequest('/mobile/login',data).then(res=>{
wx.hideLoading()
if(res){
console.log(res)
wx.setStorageSync('token', res.data.data.token)
wx.setStorageSync('userName', res.data.data.userName)
wx.setStorageSync('headUrl', res.data.data.headUrl)
wx.setStorageSync('roleId', res.data.data.roleId)
wx.setStorageSync('isLogin',true)
this.setData({
token:res.data.data.token,
userName:res.data.data.userName,
headUrl:res.data.data.headUrl,
roleId:res.data.data.roleId,
isLogin:true
})
}
})
},
fail: err => {
// console.log('登录失败!')
wx.showToast({
title: '登录失败!',
icon: 'none'
})
}
})
} else {
wx.showToast({
title: '您已拒绝授权',
icon: 'none'
})
}
},
getUserProfile(e){
wx.getUserProfile({
desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (res) => {
// this.setData({
// userInfo: res.userInfo,
// hasUserInfo: true
// })
console.log(res.userInfo)
}
})
}, },
logout(e){
wx.setStorageSync('token', '')
wx.setStorageSync('userName', '')
wx.setStorageSync('headUrl', '')
wx.setStorageSync('roleId', '')
wx.setStorageSync('isLogin',false)
this.setData({
token:'',
userName:'',
headUrl:'',
roleId:'',
isLogin:false
})
},
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment