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