let config = require('./config/config.js') const Http = require("./utils/HttpBasics"); App({ data: { }, onLaunch: function (options) { // var that = this; this.globalData.sceneAddress = options.scene; this.getLocation() this.getUserInfo() // 登录 wx.login({ success: ({ code }) => { Http.post({ url: config.api.login, data: { appId: config.weapp.AppId, code: code, sceneAddress: this.globalData.sceneAddress, } }).then(res => { // console.log("req",res); this.globalData.token = res.token; Http.setToken(res.token) Http.get({ url: config.api.checkUserStatus, data: { } }).then(statusres => { if (statusres.code == 11004) { // 用户昵称未授权 wx.redirectTo({ url: '../getuserinfo/index', }) } }) }) } }) // setTimeout(() => { // this.globalData.market={ // name:"陕西大悦城" // } // }, 1000); }, /** * 获取地址位置信息 */ getLocation: function () { wx.getLocation({ type: 'wgs84', success: function (res) { console.log("getLocation", res); }, fail: error => { console.log(error); } }) }, /** * 获取用户信息 */ 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, // 渠道 sceneAddress: null, // 二维码参数 scene: null, // 当前商场信息 market: { name: "陕西大悦城" } } })