123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- let requestTimes = 0;
- const request = (url, data, method = 'GET') => {
- return new Promise((resolve, reject) => {
- let header = {
- 'Content-Type': 'application/json',
- }
- if (uni.getStorageSync('token')) {
- header.Authorization = uni.getStorageSync('token')
- }
- if (requestTimes === 0) {
- uni.showLoading({
- title: '加载中',
- mask: true,
- });
- }
- requestTimes++;
- uni.request({
- url: url,
- data: data,
- method: method,
- header: header,
- success: res => {
- if (res.statusCode == 200) {
- let data = res.data
- if (data.status == 30001) {
- uni.removeStorageSync('token')
- if(url.indexOf('teamStatistics')==-1&&url.indexOf('center/clueRait')==-1){
- uni.navigateTo({
- url: '/pages/login/index'
- });
- }
- return false
- }
- if (data.status == 10000) {
- resolve(res.data)
- } else {
- reject(res.data)
- }
- } else {
- reject(res.data)
- }
- },
- fail: res => {
- reject(res.data)
- },
- complete: () => {
- requestTimes--;
- if (requestTimes === 0) {
- uni.hideLoading();
- }
- }
- })
- });
- }
- module.exports = {
- request: request
- }
|