Browse Source

组件数据load

tags/2.2.4
Stormeye.Wu 6 years ago
parent
commit
447dd15038
4 changed files with 59 additions and 25 deletions
  1. +9
    -11
      app.js
  2. +17
    -1
      pages/index/coupons/index.js
  3. +17
    -10
      pages/index/index.js
  4. +16
    -3
      pages/index/rushToBuy/index.js

+ 9
- 11
app.js View File

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


+ 17
- 1
pages/index/coupons/index.js View File

@@ -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
})
})
}
} }
} }
}) })

+ 17
- 10
pages/index/index.js View File

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


+ 16
- 3
pages/index/rushToBuy/index.js View File

@@ -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
})
})
}
} }
} }
}) })

Loading…
Cancel
Save