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

View File

@@ -2,4 +2,5 @@
<view class="loginImg"> <view class="loginImg">
<image src="/static/img/login_img.png" mode="widthFix"></image> <image src="/static/img/login_img.png" mode="widthFix"></image>
</view> </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, "compileHotReLoad": false,
"useMultiFrameRuntime": true, "useMultiFrameRuntime": true,
"useApiHook": true, "useApiHook": true,
"useApiHostProcess": false, "useApiHostProcess": true,
"babelSetting": { "babelSetting": {
"ignore": [], "ignore": [],
"disablePlugins": [], "disablePlugins": [],