| @@ -4,9 +4,9 @@ App({ | |||||
| data: {}, | data: {}, | ||||
| onLaunch: function(options) { | onLaunch: function(options) { | ||||
| var that = this; | var that = this; | ||||
| this.globalData.sceneAddress = options.scene; | |||||
| this.getLocation() | |||||
| this.getUserInfo() | |||||
| that.globalData.sceneAddress = options.scene; | |||||
| that.getLocation() | |||||
| that.getUserInfo() | |||||
| // 登录 | // 登录 | ||||
| wx.login({ | wx.login({ | ||||
| success: ({ | success: ({ | ||||
| @@ -17,18 +17,16 @@ App({ | |||||
| data: { | data: { | ||||
| appId: config.weapp.AppId, | appId: config.weapp.AppId, | ||||
| code: code, | code: code, | ||||
| sceneAddress: this.globalData.sceneAddress, | |||||
| sceneAddress: that.globalData.sceneAddress, | |||||
| } | } | ||||
| }).then(res => { | }).then(res => { | ||||
| // console.log("req",res); | |||||
| this.globalData.token = res.data.token; | |||||
| console.log("req",res); | |||||
| that.globalData.token = res.data.token; | |||||
| Http.setToken(res.data.token) | Http.setToken(res.data.token) | ||||
| if (that.couponChannelListCallback) { | |||||
| that.couponChannelListCallback(res.data.token); | |||||
| } | |||||
| if (that.couponListCallback) { | |||||
| that.couponListCallback(res.data.token); | |||||
| if (that.tokenCallback) { | |||||
| that.tokenCallback(res.data.token); | |||||
| } | } | ||||
| return Http.post({ | return Http.post({ | ||||
| url: config.api.checkUserStatus, | url: config.api.checkUserStatus, | ||||
| data: {} | data: {} | ||||
| @@ -66,7 +66,8 @@ Component({ | |||||
| }, | }, | ||||
| }, | }, | ||||
| ready() { | ready() { | ||||
| app.couponListCallback = token => { | |||||
| // TODO business获取 | |||||
| if (app.globalData.token && app.globalData.token != null) { | |||||
| Http.get({ | Http.get({ | ||||
| url: config.api.couponList, | url: config.api.couponList, | ||||
| data: { | data: { | ||||
| @@ -79,6 +80,21 @@ Component({ | |||||
| list: res.data.list | list: res.data.list | ||||
| }) | }) | ||||
| }) | }) | ||||
| } else { | |||||
| app.couponListCallback = token => { | |||||
| Http.get({ | |||||
| url: config.api.couponList, | |||||
| data: { | |||||
| pageNum: 1, | |||||
| pageSize: 10 | |||||
| } | |||||
| }).then(res => { | |||||
| console.log(res); | |||||
| this.setData({ | |||||
| list: res.data.list | |||||
| }) | |||||
| }) | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| }) | }) | ||||
| @@ -24,22 +24,29 @@ Page({ | |||||
| }, | }, | ||||
| onLoad: function (options) { | onLoad: function (options) { | ||||
| wx.showLoading({ | |||||
| title: '加载中', | |||||
| }) | |||||
| var scene = decodeURIComponent(options.scene); | |||||
| var that = this; | var that = this; | ||||
| if (app.globalData.openId && app.globalData.openId != null) { | |||||
| if (app.globalData.token && app.globalData.token != null) { | |||||
| } else { | } else { | ||||
| // 由于是网络请求,可能会在 Page.onLoad 之后才返回 | // 由于是网络请求,可能会在 Page.onLoad 之后才返回 | ||||
| // 所以此处加入 callback 以防止这种情况 | // 所以此处加入 callback 以防止这种情况 | ||||
| app.openIdCallback = openId => { | |||||
| console.log(openId); | |||||
| app.tokenCallback = token => { | |||||
| console.log("index + " + token); | |||||
| if (that.couponChannelListCallback) { | |||||
| that.couponChannelListCallback(res.data.token); | |||||
| } | |||||
| if (that.couponListCallback) { | |||||
| that.couponListCallback(res.data.token); | |||||
| } | |||||
| } | } | ||||
| setTimeout(function () { | |||||
| wx.hideLoading() | |||||
| }, 2200) | |||||
| } | } | ||||
| wx.showLoading({ | |||||
| title: '加载中', | |||||
| }) | |||||
| var scene = decodeURIComponent(options.scene); | |||||
| var that = this; | |||||
| setTimeout(function () { | |||||
| wx.hideLoading() | |||||
| }, 2200) | |||||
| }, | }, | ||||
| // 用户点击右上角分享 | // 用户点击右上角分享 | ||||
| onShareAppMessage: function () { | onShareAppMessage: function () { | ||||
| @@ -50,11 +50,9 @@ Component({ | |||||
| * 组件的方法列表 | * 组件的方法列表 | ||||
| */ | */ | ||||
| methods: { | methods: { | ||||
| }, | }, | ||||
| ready() { | ready() { | ||||
| app.couponChannelListCallback = token => { | |||||
| Http.setToken(token); | |||||
| if (app.globalData.token && app.globalData.token != null) { | |||||
| Http.get({ | Http.get({ | ||||
| url: config.api.couponChannelList, | url: config.api.couponChannelList, | ||||
| data: { | data: { | ||||
| @@ -66,6 +64,21 @@ Component({ | |||||
| list: res.data.list | list: res.data.list | ||||
| }) | }) | ||||
| }) | }) | ||||
| } else { | |||||
| app.couponChannelListCallback = token => { | |||||
| Http.setToken(token); | |||||
| Http.get({ | |||||
| url: config.api.couponChannelList, | |||||
| data: { | |||||
| pageNum: 1, | |||||
| pageSize: 10 | |||||
| } | |||||
| }).then(res => { | |||||
| this.setData({ | |||||
| list: res.data.list | |||||
| }) | |||||
| }) | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| }) | }) | ||||