From 7d6d4cfc006cdb0a6666bcb0dc1fcd4617f6096e Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 29 Apr 2020 10:38:46 +0800 Subject: [PATCH] =?UTF-8?q?[Update]=20=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/request.js | 43 +++++++++++++++++-------------------------- vue.config.js | 4 ++++ 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/src/utils/request.js b/src/utils/request.js index cc3000b44..975278629 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -1,4 +1,6 @@ import axios from 'axios' +import i18n from '@/i18n/i18n' + import { MessageBox, Message @@ -52,35 +54,24 @@ service.interceptors.response.use( response => { const res = response.data - // if the custom code is not 20000, it is judged as an error. - if (response.status >= 200 && response.status < 400) { - if (response.config.raw === 1) { - return response - } - return res - } else if (response.status === 50008 || response.status === 50012 || response.status === 50014) { - MessageBox.confirm('You have been logged out, you can cancel to stay on this page, or log in again', 'Confirm logout', { - confirmButtonText: 'Re-Login', - cancelButtonText: 'Cancel', - type: 'warning' - }).then(() => { - store.dispatch('user/resetToken').then(() => { - location.reload() - }) - }) - } else if (response.status === 400) { - console.log('status is 400') - return Promise.reject(res || 'Error') - } else { - Message({ - message: res.message || res.error || 'Error', - type: 'error', - duration: 5 * 1000 - }) - return Promise.reject(new Error(res.message || 'Error')) + if (response.config.raw === 1) { + return response } + return res }, error => { + const response = error.response + if (response.status === 401) { + const title = '' + const msg = i18n.t('You have been logged out, you can cancel to stay on this page, or log in again') + MessageBox.confirm(msg, title, { + confirmButtonText: i18n.t('auth.Re-Login'), + cancelButtonText: i18n.t('common.Cancel'), + type: 'warning' + }).then(() => { + window.location = '/auth/login/' + }) + } Message({ message: error.message, type: 'error', diff --git a/vue.config.js b/vue.config.js index 1067b753d..1069d9e50 100644 --- a/vue.config.js +++ b/vue.config.js @@ -46,6 +46,10 @@ module.exports = { pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' } + }, + '^/(auth|static)': { + target: `http://localhost:8080`, + changeOrigin: true } }, after: require('./mock/mock-server.js')