..
This commit is contained in:
@@ -23,6 +23,7 @@ export function useRequest() {
|
||||
const token = uni.getStorageSync('token')
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
...(token ? { 'Authorization': `Bearer ${token}` } : {}),
|
||||
...options.header
|
||||
}
|
||||
@@ -35,9 +36,21 @@ export function useRequest() {
|
||||
timeout: options.timeout || 10000,
|
||||
success: (res) => {
|
||||
if (res.statusCode >= 200 && res.statusCode < 300) {
|
||||
resolve(res.data as T)
|
||||
if(res.data.code === 0){
|
||||
resolve(res.data as T)
|
||||
}else if(res.data.code === 600098){
|
||||
// 未登录
|
||||
uni.removeStorageSync('token')
|
||||
uni.reLaunch({
|
||||
url: '/pages/login/index'
|
||||
})
|
||||
}else {
|
||||
const err = new Error(res.data?.msg || '请求失败')
|
||||
error.value = err
|
||||
reject(err)
|
||||
}
|
||||
} else {
|
||||
const err = new Error(res.data?.message || '请求失败')
|
||||
const err = new Error(res.data?.msg || '请求失败')
|
||||
error.value = err
|
||||
reject(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user