From 8984ff175562604ee374148eaf6b32a9e6910dd7 Mon Sep 17 00:00:00 2001 From: meo <18801474720@163.com> Date: Sun, 21 Oct 2018 12:47:17 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=81=9C=E8=BD=A6=E8=8E=B7=E5=BE=97token?= =?UTF-8?q?=E5=92=8C=E6=88=90=E9=95=BF=E5=80=BC][=E4=BF=AE=E6=94=B9]:?= =?UTF-8?q?=E5=81=9C=E8=BD=A6=E8=8E=B7=E5=BE=97token=E5=92=8C=E6=88=90?= =?UTF-8?q?=E9=95=BF=E5=80=BC=20=20=20=20=E9=95=BF=E8=9E=8D2.1.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/passCar/passCar.js | 112 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 110 insertions(+), 2 deletions(-) diff --git a/pages/passCar/passCar.js b/pages/passCar/passCar.js index 4fa48ab..c33ebec 100644 --- a/pages/passCar/passCar.js +++ b/pages/passCar/passCar.js @@ -119,9 +119,117 @@ Page({ title: weapNote.carpage.title }) }); + // 登录 + var scene = decodeURIComponent(options.scene); + that.setData({ + scene: scene + }); + app.getLocation(); + if (app.globalData.token){}else{ + that.userLogin() + } + }, + /** + * 用户登录 + */ + userLogin: function () { + var that = this; + // 登录 + wx.login({ + success: ({ + code + }) => { + wx.getSystemInfo({ + success: function (res) { + that.setData({ + systemInfo: JSON.stringify(res) + }) + } + }) + var usrdata = { + appId: config.weapp.AppId, + code: code, + sceneAddress: app.globalData.sceneAddress, + scene: that.data.scene, + systemInfo: that.data.systemInfo + }; + if (app.globalData.locationInfo) { + usrdata = { + appId: config.weapp.AppId, + code: code, + sceneAddress: app.globalData.sceneAddress, + latitude: "" + app.globalData.locationInfo.latitude, + longitude: "" + app.globalData.locationInfo.longitude, + scene: that.data.scene, + systemInfo: that.data.systemInfo + }; + } + Http.post({ + url: config.api.login, + data: usrdata + }) + .then(res => { + app.globalData.token = res.data.token; + Http.setToken(res.data.token); + that.checkUserCarStatus(); + that.getUserInfo(); + return Http.post({ + url: config.api.checkUserStatus, + data: {} + }); + }) + .then(res => { + console.log("checkUserStatus:res", res); + }) + .catch(err => { + console.log("checkUserStatus:err", err); + if (err.code == 11004) { + // 用户昵称未授权 + wx.redirectTo({ + url: "/pages/getuserinfo/index" + }); + } + }); + } + }); + }, + /** + * 检查用户是否有车 + */ + checkUserCarStatus: function () { + var that = this; + Http.get({ + url: config.api.userCarCount, + data: {} + }).then(res => { + if (res.data > 0) { + // 用户名下有车 + app.globalData.phone = res.data.phone; + app.globalData.supportCar = true; + // 共同登录 + that.userCarLogin(); + } + }); + }, + /** + * 获取用户信息 + */ + getUserInfo: function () { + // 获取用户信息 + wx.getSetting({ + success: res => { + if (res.authSetting["scope.userInfo"]) { + // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框 + wx.getUserInfo({ + success: res => { + // 可以将 res 发送给后台解码出 unionId + console.log("getUserInfo", res); + } + }); + } + } + }) }, - - jumpToAdd: function() { wx.navigateTo({ url: `/pages/addPark/addPark?flags=managepalte`