包装 wx.request 方法为 app.request

wechat_user_type
Ge Hao 8 years ago
parent cafafa8005
commit e3214b07a9
  1. 29
      app.js
  2. 2
      pages/cart/cart.wxml
  3. 7
      pages/cart/cart.wxss
  4. 9
      pages/cart/coupon.js
  5. 2
      utils/address.js
  6. 5
      utils/order.js
  7. 6
      utils/product.js
  8. 4
      utils/profile.js

@ -32,6 +32,35 @@ App({
}
},
request: function(obj) {
var header = obj.header || {}
if (!header['content-type']) {
header['content-type'] = 'application/json'
}
if (!header['Authorization']) {
header['Authorization'] = getApp().globalData.token
}
wx.request({
url: obj.url,
data: obj.data || {},
method: obj.method || 'GET',
header: header,
success: function(res) {
if (res.statusCode === 401) {
}
typeof obj.success == "function" && obj.success(res)
},
fail: obj.fail || function() {},
complete: obj.complete || function() {}
})
},
authRequest: function(obj) {
function unauthorizeCallback() {}
},
globalData:{
userInfo: null,
currentCustomer: null,

@ -16,7 +16,7 @@
</view>
<view class="separate"></view>
<view bindtap="bindSelectCoupon">
<view class="use-coupon" bindtap="bindSelectCoupon">
<view><text>使用优惠券</text></view>
</view>

@ -24,6 +24,7 @@
.item {
height: 180rpx;
padding: 15rpx;
padding-left: 10rpx;
background-color: #fff;
border-bottom: 1px solid #e4e4e4;
color: #333;
@ -115,4 +116,10 @@
.separate {
height: 18rpx;
background-color: #f2f2f2;
}
.use-coupon {
font-size: 30rpx;
line-height: 55rpx;
margin-left: 15rpx;
}

@ -17,19 +17,12 @@ Page({
// var data = wx.getStorageSync('coupons')
// this.setData({coupons: data})
var that = this
var data = {}
data['token'] = app.globalData.token
wx.request({
app.request({
url: `${app.globalData.API_URL}/coupons`,
data: data,
method: 'GET',
success: function(res){
var data = app.store.sync(res.data)
that.setData({coupons: data})
},
fail: function() {
},
complete: function() {
}
})
}

@ -1,7 +1,7 @@
const app = getApp()
function postAddress (data) {
wx.request({
app.request({
method: 'POST',
url: `${app.globalData.API_URL}/addresses/new`,
data: Object.assign({}, data),

@ -1,11 +1,10 @@
const app = getApp()
function postBilling (data, resolve) {
data['token'] = app.globalData.token
wx.request({
app.request({
method: 'POST',
url: `${app.globalData.API_URL}/orders/create_applet_order`,
data: data,
data: data || {},
header: { 'Content-Type': 'application/json'},
success: resolve,
fail: function(){}

@ -1,7 +1,7 @@
const app = getApp()
function getProducts (resolve) {
wx.request({
app.request({
url: `${app.globalData.API_URL}/products`,
header: { 'Content-Type': 'application/json' },
success: resolve,
@ -10,7 +10,7 @@ function getProducts (resolve) {
}
function getSlides (resolve) {
wx.request({
app.request({
url: `${app.globalData.API_URL}/home_slides`,
header: { 'Content-Type': 'application/json' },
success: resolve,
@ -19,7 +19,7 @@ function getSlides (resolve) {
}
function getCategories (data, resolve, reject) {
wx.request({
app.request({
url: `${app.globalData.API_URL}/products?type=${data}`,
header: { 'Content-Type': 'application/json'},
success: resolve,

@ -1,7 +1,7 @@
const app = getApp()
function getZichanSlides (resolve) {
wx.request({
app.request({
url: `${app.globalData.API_URL}/my_assets`,
data: {token: app.globalData.token},
header: { 'Content-Type': 'application/json'},
@ -45,7 +45,7 @@ function getCustomerInfo (data, cb) {
}
function getPassCode (mobile, cb) {
wx.request({
app.request({
url: `${app.globalData.API_URL}/send_validation_code/send_message`,
header: { 'Content-Type': 'application/json'},
data: {

Loading…
Cancel
Save