From 7dc650922a69ef032dc446f1a3f81cfc379e695c Mon Sep 17 00:00:00 2001 From: fengchenchen Date: Wed, 17 Nov 2021 20:43:42 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90bug=E3=80=91-=20=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E7=BA=BF=E4=B8=8A=E7=89=88=E6=9C=AC=E9=A6=96=E6=AC=A1=E4=B8=8D?= =?UTF-8?q?=E8=83=BD=E6=8E=88=E6=9D=83=E7=99=BB=E5=BD=95=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/login/login.js | 98 ++++++++++++++++++++++++++++---------------- 1 file changed, 62 insertions(+), 36 deletions(-) diff --git a/pages/login/login.js b/pages/login/login.js index ef80088..cab58b5 100644 --- a/pages/login/login.js +++ b/pages/login/login.js @@ -97,6 +97,7 @@ Page({ wx.getStorage({ key: 'authorize', success(result){ + console.log('result=======', result) // 做过查看微信用户信息 if(result.data){ // 做过用户信息获取 wx.showToast({ @@ -137,6 +138,7 @@ Page({ }, fail(err){ // 没有做过查看微信用户信息 + console.log('err========', err) that.getUserInfo() } }) @@ -144,51 +146,75 @@ Page({ // 获取用户信息,微信登录 getUserInfo(){ const that = this - wx.getUserProfile({ - desc: '用于完善用户信息', - success(result){ - let userInfoTemp = JSON.parse(result.rawData) - wx.setStorage({ - key: 'userInfoTemp', - data: userInfoTemp - }) - that.setData({ - userInfoTemp - }) - wx.showToast({ - title: '登录中...', - icon: 'loading' - }) - wxBind((res)=>{ - let params = { - openId: res.data.openid, - rsaPublicKey: that.data.rsaPublicKey - } - UserApi.wxLogin(params).then(res=>{ - if(res.success) {// 已经用手机号登录过,此时用微信快捷登录时,把微信的个人信息存进缓存(微信信息在缓存的userInfoTemp) - wx.setStorageSync('userInfo', res.result.userInfo) + wx.showModal({ + title: '温馨提示', + content: `亲,授权微信登录后才能正常使用小程序功能`, + cancelColor: 'cancelColor', + success(res) { + if (res.confirm) { + wx.getUserProfile({ + desc: '获取你的昵称、头像、地区及性别', + success(result){ + console.log('result用于完善用户信息', result) + let userInfoTemp = JSON.parse(result.rawData) wx.setStorage({ - key: 'X-Access-Token', - data: res.result.token + key: 'userInfoTemp', + data: userInfoTemp }) - wx.switchTab({ - url: '../home/home', + that.setData({ + userInfoTemp }) - wx.setStorageSync('authorize', true) // 设置有过微信授权 - wx.setStorageSync('avatarUrl', that.data.userInfoTemp.avatarUrl) - }else{ // 首次登录不能直接用微信快捷登录 wx.showToast({ - title: '暂无授权手机号', - icon: 'none' + title: '登录中...', + icon: 'loading' }) + wxBind((res)=>{ + let params = { + openId: res.data.openid, + rsaPublicKey: that.data.rsaPublicKey + } + UserApi.wxLogin(params).then(res=>{ + if(res.success) {// 已经用手机号登录过,此时用微信快捷登录时,把微信的个人信息存进缓存(微信信息在缓存的userInfoTemp) + wx.setStorageSync('userInfo', res.result.userInfo) + wx.setStorage({ + key: 'X-Access-Token', + data: res.result.token + }) + wx.switchTab({ + url: '../home/home', + }) + wx.setStorageSync('authorize', true) // 设置有过微信授权 + wx.setStorageSync('avatarUrl', that.data.userInfoTemp.avatarUrl) + }else{ // 首次登录不能直接用微信快捷登录 + wx.showToast({ + title: '暂无授权手机号', + icon: 'none' + }) + } + }) + }) + }, + fail(err){ + console.log('err===========', err) + wx.setStorageSync('authorize', false) } }) - }) - }, - fail(err){ - wx.setStorageSync('authorize', false) + } else { + + } } }) + // wx.showModal({ + // title: '错误提示', + // content: `图片大于${that.data.maxSize}MB`, + // showCancel: false, + // success(res) { + // if (res.confirm) { + // console.log('用户点击确定') + // } + // } + // }) + }, // 登录 formSubmit(e) {