diff --git a/package.json b/package.json index d58a96b4..3aa410ad 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 38deb2f0..7407baf0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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 dayjs: ^1.11.5 element-plus: ^2.2.18 eslint: ^8.25.0 @@ -62,8 +62,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 @@ -1308,7 +1308,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: '*' @@ -1345,7 +1345,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: @@ -1595,11 +1595,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 @@ -3535,6 +3536,17 @@ packages: peerDependenciesMeta: debug: optional: true + dev: true + + /follow-redirects/1.15.2: + resolution: {integrity: sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==} + engines: {node: '>=4.0'} + peerDependencies: + debug: '*' + peerDependenciesMeta: + debug: + optional: true + dev: false /for-each/0.3.3: resolution: {integrity: sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==} @@ -5914,6 +5926,10 @@ packages: resolution: {integrity: sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==} 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 diff --git a/src/api/index.ts b/src/api/index.ts index 7a723bcf..808350a4 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -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