From 447dd1503817295aa28e413f27cd5b62c603a5d7 Mon Sep 17 00:00:00 2001 From: "Stormeye.Wu" Date: Thu, 23 Aug 2018 16:39:24 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=84=E4=BB=B6=E6=95=B0=E6=8D=AEload?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 20 +++++++++----------- pages/index/coupons/index.js | 18 +++++++++++++++++- pages/index/index.js | 27 +++++++++++++++++---------- pages/index/rushToBuy/index.js | 19 ++++++++++++++++--- 4 files changed, 59 insertions(+), 25 deletions(-) diff --git a/app.js b/app.js index 59a4671..9eea4f3 100644 --- a/app.js +++ b/app.js @@ -4,9 +4,9 @@ App({ data: {}, onLaunch: function(options) { var that = this; - this.globalData.sceneAddress = options.scene; - this.getLocation() - this.getUserInfo() + that.globalData.sceneAddress = options.scene; + that.getLocation() + that.getUserInfo() // 登录 wx.login({ success: ({ @@ -17,18 +17,16 @@ App({ data: { appId: config.weapp.AppId, code: code, - sceneAddress: this.globalData.sceneAddress, + sceneAddress: that.globalData.sceneAddress, } }).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) - 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({ url: config.api.checkUserStatus, data: {} diff --git a/pages/index/coupons/index.js b/pages/index/coupons/index.js index 22c012a..5059eb9 100644 --- a/pages/index/coupons/index.js +++ b/pages/index/coupons/index.js @@ -66,7 +66,8 @@ Component({ }, }, ready() { - app.couponListCallback = token => { + // TODO business获取 + if (app.globalData.token && app.globalData.token != null) { Http.get({ url: config.api.couponList, data: { @@ -79,6 +80,21 @@ Component({ 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 + }) + }) + } } } }) \ No newline at end of file diff --git a/pages/index/index.js b/pages/index/index.js index c33444d..58ffc36 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -24,22 +24,29 @@ Page({ }, onLoad: function (options) { - wx.showLoading({ - title: '加载中', - }) - var scene = decodeURIComponent(options.scene); var that = this; - if (app.globalData.openId && app.globalData.openId != null) { + if (app.globalData.token && app.globalData.token != null) { } else { // 由于是网络请求,可能会在 Page.onLoad 之后才返回 // 所以此处加入 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 () { diff --git a/pages/index/rushToBuy/index.js b/pages/index/rushToBuy/index.js index 64c387e..5401ef3 100644 --- a/pages/index/rushToBuy/index.js +++ b/pages/index/rushToBuy/index.js @@ -50,11 +50,9 @@ Component({ * 组件的方法列表 */ methods: { - }, ready() { - app.couponChannelListCallback = token => { - Http.setToken(token); + if (app.globalData.token && app.globalData.token != null) { Http.get({ url: config.api.couponChannelList, data: { @@ -66,6 +64,21 @@ Component({ 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 + }) + }) + } } } }) \ No newline at end of file