123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- let ajaxTimes = 0;
- const request = (url, data, method = 'GET') => {
- return new Promise((resolve, reject) => {
- let header = {
- 'Content-Type': 'application/json',
- }
- if (uni.getStorageSync('token')) {
- header.token = 'Bearer ' + uni.getStorageSync('token')
- }
- if (url.indexOf('app/product/user/auctionProductDetail/biddingHall/') == -1) {
- ajaxTimes++;
- uni.showLoading({
- title: "加载中",
- mask: true,
- });
- }
- uni.request({
- url: url,
- data: data,
- method: method,
- header: header,
- success: res => {
- if (res.statusCode == 200) {
- let data = res.data
- if (data.code == 40001 || data.code == 40002 || data.code == 40003 || data.code == 40004 || data.code ==
- 40005) {
- uni.clearStorageSync()
- uni.navigateTo({
- url: '/pages/index/login'
- });
- return false
- }
- if (data.code == 0 || data.code == 200) {
- resolve(res.data)
- } else {
- reject(res)
- }
- } else {
- reject(res)
- }
- },
- fail: res => {
- reject(res)
- },
- complete: () => {
- if (url.indexOf('app/product/user/auctionProductDetail/biddingHall/') == -1) {
- ajaxTimes--;
- }
- if (ajaxTimes === 0) {
- uni.hideLoading();
- }
- }
- })
- });
- }
- module.exports = {
- request: request
- }
|