| | |
| | | import axios from 'axios' |
| | | import store from '@/store/' |
| | | import router from '@/router/' |
| | | import { serialize } from '@/utils/util' |
| | | import { logOutFun, serialize } from '@/utils/util' |
| | | import { getToken, removeToken, removeRefreshToken } from '@/utils/auth' |
| | | import { isURL, validatenull } from '@/utils/validate' |
| | | import { ElMessage } from 'element-plus' |
| | |
| | | //跨域请求,允许保存cookie |
| | | axios.defaults.withCredentials = true |
| | | |
| | | function logOutFun() { |
| | | store.dispatch('FedLogOut').then(() =>{ |
| | | const {VITE_APP_PARENT_SYSTEM,VITE_APP_ENV} = import.meta.env |
| | | const isDev = VITE_APP_ENV === 'development' |
| | | isDev |
| | | ? router.push({ path: '/login' }) |
| | | : window.location.replace(`${VITE_APP_PARENT_SYSTEM}/#/login`) |
| | | }) |
| | | } |
| | | |
| | | //http request拦截 |
| | | axios.interceptors.request.use( |
| | |
| | | const currentRouteName = router.currentRoute.value.name |
| | | // 如果当前路由不是登录页,则跳转到登录页 |
| | | if (currentRouteName !== '登录页') { |
| | | store.dispatch('FedLogOut').then(() => |
| | | router.push({ |
| | | path: '/login', |
| | | }) |
| | | ) |
| | | logOutFun() |
| | | } |
| | | return Promise.reject(new Error(message)) |
| | | } |