mirror of
https://gitee.com/fantastic-admin/basic.git
synced 2024-11-29 18:48:31 +08:00
refactor: 优化拦截器
This commit is contained in:
parent
8771b33834
commit
5bbde8d102
@ -20,7 +20,7 @@
|
||||
"@tinymce/tinymce-vue": "^5.0.0",
|
||||
"@vueuse/core": "^9.3.0",
|
||||
"@vueuse/integrations": "^9.3.0",
|
||||
"axios": "^0.27.2",
|
||||
"axios": "^1.1.3",
|
||||
"dayjs": "^1.11.5",
|
||||
"element-plus": "^2.2.18",
|
||||
"hotkeys-js": "^3.10.0",
|
||||
|
@ -13,7 +13,7 @@ specifiers:
|
||||
'@vueuse/core': ^9.3.0
|
||||
'@vueuse/integrations': ^9.3.0
|
||||
autoprefixer: ^10.4.12
|
||||
axios: ^0.27.2
|
||||
axios: ^1.1.3
|
||||
bumpp: ^8.2.1
|
||||
cz-git: ^1.3.11
|
||||
dayjs: ^1.11.5
|
||||
@ -64,8 +64,8 @@ specifiers:
|
||||
dependencies:
|
||||
'@tinymce/tinymce-vue': 5.0.0_vue@3.2.41
|
||||
'@vueuse/core': 9.3.0_vue@3.2.41
|
||||
'@vueuse/integrations': 9.3.0_sxi4m5kr6bbdnscpdwfcjzgbqa
|
||||
axios: 0.27.2
|
||||
'@vueuse/integrations': 9.3.0_gtyxodlhilt3tzbhddzjsu5dxq
|
||||
axios: 1.1.3
|
||||
dayjs: 1.11.5
|
||||
element-plus: 2.2.18_vue@3.2.41
|
||||
hotkeys-js: 3.10.0
|
||||
@ -1292,7 +1292,7 @@ packages:
|
||||
- '@vue/composition-api'
|
||||
- vue
|
||||
|
||||
/@vueuse/integrations/9.3.0_sxi4m5kr6bbdnscpdwfcjzgbqa:
|
||||
/@vueuse/integrations/9.3.0_gtyxodlhilt3tzbhddzjsu5dxq:
|
||||
resolution: {integrity: sha512-KkJpC97VioZUpSw7rvgnqoLgTztLlLLGdYp6WQKn69cJiItsJVSRZrmI+X9YVxPBzuLvRymYZfp0RMyISVFHTw==}
|
||||
peerDependencies:
|
||||
async-validator: '*'
|
||||
@ -1329,7 +1329,7 @@ packages:
|
||||
dependencies:
|
||||
'@vueuse/core': 9.3.0_vue@3.2.41
|
||||
'@vueuse/shared': 9.3.0_vue@3.2.41
|
||||
axios: 0.27.2
|
||||
axios: 1.1.3
|
||||
nprogress: 0.2.0
|
||||
vue-demi: 0.13.6_vue@3.2.41
|
||||
transitivePeerDependencies:
|
||||
@ -1579,11 +1579,12 @@ packages:
|
||||
resolution: {integrity: sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==}
|
||||
dev: true
|
||||
|
||||
/axios/0.27.2:
|
||||
resolution: {integrity: sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==}
|
||||
/axios/1.1.3:
|
||||
resolution: {integrity: sha512-00tXVRwKx/FZr/IDVFt4C+f9FYairX517WoGCL6dpOntqLkZofjhu43F/Xl44UOpqa+9sLFDrG/XAnFsUYgkDA==}
|
||||
dependencies:
|
||||
follow-redirects: 1.15.1
|
||||
follow-redirects: 1.15.2
|
||||
form-data: 4.0.0
|
||||
proxy-from-env: 1.1.0
|
||||
transitivePeerDependencies:
|
||||
- debug
|
||||
dev: false
|
||||
@ -3537,8 +3538,8 @@ packages:
|
||||
resolution: {integrity: sha512-0sQoMh9s0BYsm+12Huy/rkKxVu4R1+r96YX5cG44rHV0pQ6iC3Q+mkoMFaGWObMFYQxCVT+ssG1ksneA2MI9KQ==}
|
||||
dev: true
|
||||
|
||||
/follow-redirects/1.15.1:
|
||||
resolution: {integrity: sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA==}
|
||||
/follow-redirects/1.15.2:
|
||||
resolution: {integrity: sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==}
|
||||
engines: {node: '>=4.0'}
|
||||
peerDependencies:
|
||||
debug: '*'
|
||||
@ -4042,7 +4043,7 @@ packages:
|
||||
engines: {node: '>=8.0.0'}
|
||||
dependencies:
|
||||
eventemitter3: 4.0.7
|
||||
follow-redirects: 1.15.1
|
||||
follow-redirects: 1.15.2
|
||||
requires-port: 1.0.0
|
||||
transitivePeerDependencies:
|
||||
- debug
|
||||
@ -5942,6 +5943,10 @@ packages:
|
||||
sisteransi: 1.0.5
|
||||
dev: true
|
||||
|
||||
/proxy-from-env/1.1.0:
|
||||
resolution: {integrity: sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==}
|
||||
dev: false
|
||||
|
||||
/psl/1.9.0:
|
||||
resolution: {integrity: sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag==}
|
||||
dev: true
|
||||
|
@ -4,6 +4,7 @@ import router from '@/router/index'
|
||||
import useUserStore from '@/store/modules/user'
|
||||
|
||||
const toLogin = () => {
|
||||
useUserStore().logout()
|
||||
router.push({
|
||||
path: '/login',
|
||||
query: {
|
||||
@ -14,7 +15,7 @@ const toLogin = () => {
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: import.meta.env.DEV && import.meta.env.VITE_OPEN_PROXY === 'true' ? '/proxy/' : import.meta.env.VITE_APP_API_BASEURL,
|
||||
timeout: 10000,
|
||||
timeout: 1000 * 60,
|
||||
responseType: 'json',
|
||||
})
|
||||
|
||||
@ -47,11 +48,7 @@ api.interceptors.response.use(
|
||||
* 请求出错时 error 会返回错误信息
|
||||
*/
|
||||
if (response.data.status === 1) {
|
||||
if (response.data.error === '') {
|
||||
// 请求成功并且没有报错
|
||||
return Promise.resolve(response.data)
|
||||
}
|
||||
else {
|
||||
if (response.data.error !== '') {
|
||||
// 这里做错误提示,如果使用了 element plus 则可以使用 Message 进行提示
|
||||
// ElMessage.error(options)
|
||||
return Promise.reject(response.data)
|
||||
@ -60,6 +57,7 @@ api.interceptors.response.use(
|
||||
else {
|
||||
toLogin()
|
||||
}
|
||||
return Promise.resolve(response.data)
|
||||
},
|
||||
(error) => {
|
||||
let message = error.message
|
||||
|
Loading…
Reference in New Issue
Block a user