|
|
|
@ -1,16 +1,7 @@ |
|
|
|
|
import config from '@/config/request' |
|
|
|
|
let HTTP_COUNT = 0 // loading次数
|
|
|
|
|
let logouted = 0 |
|
|
|
|
|
|
|
|
|
const request = options => { |
|
|
|
|
HTTP_COUNT++ |
|
|
|
|
if (config.showLoading) { |
|
|
|
|
// 请求数据时的loading
|
|
|
|
|
// uni.showToast({
|
|
|
|
|
// title: '加载中',
|
|
|
|
|
// duration: 200,
|
|
|
|
|
// icon: 'loading'
|
|
|
|
|
// })
|
|
|
|
|
} |
|
|
|
|
const header = Object.assign({}, config.headers, { |
|
|
|
|
token: uni.getStorageSync('token') |
|
|
|
|
}) |
|
|
|
@ -29,18 +20,22 @@ const request = options => { |
|
|
|
|
if (status === 200) { |
|
|
|
|
resolve(data) |
|
|
|
|
} else if (status == 401) { |
|
|
|
|
// 登录过期
|
|
|
|
|
uni.clearStorageSync() |
|
|
|
|
uni.showToast({ |
|
|
|
|
title: message, |
|
|
|
|
icon: 'none' |
|
|
|
|
}) |
|
|
|
|
setTimeout(() => { |
|
|
|
|
uni.navigateTo({ |
|
|
|
|
url: '../login/login' |
|
|
|
|
if (!logouted) { |
|
|
|
|
// 登录过期
|
|
|
|
|
uni.clearStorageSync() |
|
|
|
|
uni.showToast({ |
|
|
|
|
title: message, |
|
|
|
|
icon: 'none' |
|
|
|
|
}) |
|
|
|
|
}, 1500) |
|
|
|
|
reject(data) |
|
|
|
|
setTimeout(() => { |
|
|
|
|
logouted = 0 |
|
|
|
|
uni.reLaunch({ |
|
|
|
|
url: '/pages/index/index' |
|
|
|
|
}) |
|
|
|
|
}, 1500) |
|
|
|
|
reject(data) |
|
|
|
|
logouted = 1 |
|
|
|
|
} |
|
|
|
|
} else if (!status) { |
|
|
|
|
resolve(data) |
|
|
|
|
} else { |
|
|
|
@ -58,12 +53,6 @@ const request = options => { |
|
|
|
|
}) |
|
|
|
|
reject(err) |
|
|
|
|
}, |
|
|
|
|
complete: () => { |
|
|
|
|
if (config.showLoading) { |
|
|
|
|
// HTTP_COUNT--
|
|
|
|
|
// HTTP_COUNT || uni.hideLoading()
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|