@@ -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: {} | |||
@@ -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 | |||
}) | |||
}) | |||
} | |||
} | |||
} | |||
}) |
@@ -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 () { | |||
@@ -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 | |||
}) | |||
}) | |||
} | |||
} | |||
} | |||
}) |