包装 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:{ globalData:{
userInfo: null, userInfo: null,
currentCustomer: null, currentCustomer: null,

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

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

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

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

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

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

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

Loading…
Cancel
Save