From e4752f75b755ee851573c11608a56f7d11adc546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=85=A2=E6=85=A2?= <994797151@qq.com> Date: Tue, 25 May 2021 14:00:28 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=9B=B4=E6=96=B0]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/login/login.js | 64 +++++++++++++++++++++++------------------- pages/login/login.wxml | 3 +- project.config.json | 2 +- 3 files changed, 38 insertions(+), 31 deletions(-) diff --git a/pages/login/login.js b/pages/login/login.js index 5c792e3..3d3cf09 100644 --- a/pages/login/login.js +++ b/pages/login/login.js @@ -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; + } + }) }, /** diff --git a/pages/login/login.wxml b/pages/login/login.wxml index d72aee6..23d8dbd 100644 --- a/pages/login/login.wxml +++ b/pages/login/login.wxml @@ -2,4 +2,5 @@ - \ No newline at end of file + + \ No newline at end of file diff --git a/project.config.json b/project.config.json index 070976e..35eb3c7 100644 --- a/project.config.json +++ b/project.config.json @@ -23,7 +23,7 @@ "compileHotReLoad": false, "useMultiFrameRuntime": true, "useApiHook": true, - "useApiHostProcess": false, + "useApiHostProcess": true, "babelSetting": { "ignore": [], "disablePlugins": [],