This commit is contained in:
那些花儿
2025-04-25 08:48:11 +08:00
parent 94656c9449
commit 89c2b07ca9
19 changed files with 1702 additions and 1604 deletions
+15 -2
View File
@@ -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)
}