1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- 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 ='Bearer ' + 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')
- uni.reLaunch({
- url: '/pages/login/index'
- });
- return false
- }
- if (data.code == 200 || data.status == 200) {
- resolve(res.data)
- } else {
- reject(res.data)
- }
- } else {
- reject(res.data)
- }
- },
- fail: res => {
- console.log('11111')
- reject(res.data)
- },
- complete: () => {
- requestTimes--;
- if (requestTimes === 0) {
- uni.hideLoading();
- }
- }
- })
- });
- }
- module.exports = {
- request: request
- }
|