From 101612691e6ea4b6a90d7554ca3e9936db8daab2 Mon Sep 17 00:00:00 2001 From: "Stormeye.Wu" Date: Fri, 17 Aug 2018 17:25:25 +0800 Subject: [PATCH] =?UTF-8?q?[c=E7=AB=AF=E5=B0=8F=E7=A8=8B=E5=BA=8F][?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D]:=E4=BB=A3=E7=A0=81=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/app.js b/app.js index 7484349..dc32f94 100644 --- a/app.js +++ b/app.js @@ -22,28 +22,8 @@ App({ console.log(result) that.globalData.token = result.data.data.token; console.log(that.globalData.token) - - // 获取用户信息 - wx.getSetting({ - success: res => { - if (res.authSetting['scope.userInfo']) { - // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框 - wx.getUserInfo({ - success: res => { - // 可以将 res 发送给后台解码出 unionId - this.globalData.userInfo = res.userInfo - - // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回 - // 所以此处加入 callback 以防止这种情况 - if (this.userInfoReadyCallback) { - this.userInfoReadyCallback(res) - } - } - }) - } - } - }) - this.getLocation() + that.getUserInfo() + that.getLocation() } }) } @@ -69,6 +49,31 @@ App({ } }) }, + /** + * 获取用户信息 + */ + getUserInfo: function() { + // 获取用户信息 + wx.getSetting({ + success: res => { + if (res.authSetting['scope.userInfo']) { + // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框 + wx.getUserInfo({ + success: res => { + // 可以将 res 发送给后台解码出 unionId + this.globalData.userInfo = res.userInfo + + // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回 + // 所以此处加入 callback 以防止这种情况 + if (this.userInfoReadyCallback) { + this.userInfoReadyCallback(res) + } + } + }) + } + } + }) + }, globalData: { // token token: null,