This commit is contained in:
张慢慢
2021-05-25 14:00:28 +08:00
parent 4b6e9d9e91
commit e4752f75b7
3 changed files with 38 additions and 31 deletions

View File

@@ -43,41 +43,47 @@ Page({
},
/**
* 登录
* 微信授权登录
*/
userInfo(e){
if(e.detail.errMsg == "getUserInfo:ok"){
this.setData({
isLogin : true,
userInfo : e.detail.rawData,
iv : e.detail.iv,
encryptedData : e.detail.encryptedData
})
// 检查用户登录Code是否过期
wx.checkSession({
success: res=>{
this.userLogin()
},
fail: err=>{
// 登录过期重新获取code
wx.login({
getuserInfo() {
wx.getUserProfile({
desc : "获取你的昵称、头像、地区及性别",
success : e => {
console.log(e)
if(e.errMsg == "getUserProfile:ok"){
this.setData({
isLogin : true,
userInfo : e.rawData,
iv : e.iv,
encryptedData : e.encryptedData
})
// 检查用户登录Code是否过期
wx.checkSession({
success: res=>{
this.setData({
loginCode: res.code
})
// 登录
console.log(res)
this.userLogin()
},
fail: err=>{
// 登录过期重新获取code
wx.login({
success: res=>{
this.setData({
loginCode: res.code
})
// 登录
this.userLogin()
}
})
}
})
}
})
}else{
wx.showToast({
title: '拒绝了登录授权',
icon : 'none'
})
}
},
fail : res => {
//拒绝授权
this.showErrorModal('拒绝了请求');
return;
}
})
},
/**

View File

@@ -2,4 +2,5 @@
<view class="loginImg">
<image src="/static/img/login_img.png" mode="widthFix"></image>
</view>
<button class="loginBtn" size="mini" hover-class="none" open-type="getUserInfo" bindgetuserinfo="userInfo" lang="zh_CN" disabled="{{isLogin}}">用户授权</button>
<button class="loginBtn" size="mini" hover-class="none" bindtap="getuserInfo" disabled="{{isLogin}}">用户授权</button>

View File

@@ -23,7 +23,7 @@
"compileHotReLoad": false,
"useMultiFrameRuntime": true,
"useApiHook": true,
"useApiHostProcess": false,
"useApiHostProcess": true,
"babelSetting": {
"ignore": [],
"disablePlugins": [],