feat 首页不登陆
This commit is contained in:
68
utils/api.js
68
utils/api.js
@@ -22,6 +22,7 @@ const request = (options) => {
|
||||
console.log('Data:', options.data)
|
||||
|
||||
const token = storage.getToken()
|
||||
const { noAuthModal = false } = options
|
||||
|
||||
uni.request({
|
||||
url: fullUrl,
|
||||
@@ -106,16 +107,24 @@ const request = (options) => {
|
||||
storage.removeRefreshToken()
|
||||
storage.removeUserInfo()
|
||||
|
||||
uni.showModal({
|
||||
title: '登录过期',
|
||||
content: '请重新登录',
|
||||
showCancel: false,
|
||||
success: () => {
|
||||
uni.reLaunch({
|
||||
url: '/pages/login/login'
|
||||
})
|
||||
}
|
||||
})
|
||||
if (!noAuthModal) {
|
||||
uni.showModal({
|
||||
title: '登录过期',
|
||||
content: '请重新登录',
|
||||
showCancel: false,
|
||||
success: () => {
|
||||
uni.reLaunch({
|
||||
url: '/pages/login/login'
|
||||
})
|
||||
}
|
||||
})
|
||||
} else {
|
||||
// 不弹出窗口,直接返回错误
|
||||
const error = new Error('401 Unauthorized')
|
||||
error.statusCode = 401
|
||||
reject(error)
|
||||
return
|
||||
}
|
||||
|
||||
reject(refreshError)
|
||||
}
|
||||
@@ -126,22 +135,26 @@ const request = (options) => {
|
||||
console.error('=== 业务错误 ===')
|
||||
console.error('Code:', data.code)
|
||||
console.error('Message:', data.message)
|
||||
uni.showModal({
|
||||
title: '请求失败',
|
||||
content: data.message || '服务器返回错误',
|
||||
showCancel: false
|
||||
})
|
||||
if (!noAuthModal) {
|
||||
uni.showModal({
|
||||
title: '请求失败',
|
||||
content: data.message || '服务器返回错误',
|
||||
showCancel: false
|
||||
})
|
||||
}
|
||||
reject(data)
|
||||
}
|
||||
} else {
|
||||
console.error('=== HTTP错误 ===')
|
||||
console.error('StatusCode:', statusCode)
|
||||
console.error('Response:', data)
|
||||
uni.showModal({
|
||||
title: '网络错误',
|
||||
content: `状态码: ${statusCode}`,
|
||||
showCancel: false
|
||||
})
|
||||
if (!noAuthModal) {
|
||||
uni.showModal({
|
||||
title: '网络错误',
|
||||
content: `状态码: ${statusCode}`,
|
||||
showCancel: false
|
||||
})
|
||||
}
|
||||
reject(res)
|
||||
}
|
||||
},
|
||||
@@ -161,11 +174,13 @@ const request = (options) => {
|
||||
}
|
||||
}
|
||||
|
||||
uni.showModal({
|
||||
title: '错误',
|
||||
content: errorMsg,
|
||||
showCancel: false
|
||||
})
|
||||
if (!noAuthModal) {
|
||||
uni.showModal({
|
||||
title: '错误',
|
||||
content: errorMsg,
|
||||
showCancel: false
|
||||
})
|
||||
}
|
||||
reject(err)
|
||||
}
|
||||
})
|
||||
@@ -216,7 +231,8 @@ const api = {
|
||||
data: {
|
||||
page,
|
||||
page_size: pageSize
|
||||
}
|
||||
},
|
||||
noAuthModal: true
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user