| | |
| | | import axios from 'axios'; |
| | | import store from '@/store/'; |
| | | import router from '@/router/'; |
| | | import { |
| | | serialize |
| | | } from '@/utils/util'; |
| | | import { |
| | | getToken, |
| | | removeToken, |
| | | removeRefreshToken |
| | | } from '@/utils/auth'; |
| | | import { |
| | | isURL, |
| | | validatenull |
| | | } from '@/utils/validate'; |
| | | import { |
| | | ElMessage |
| | | } from 'element-plus'; |
| | | import { serialize } from '@/utils/util'; |
| | | import { getToken, removeToken, removeRefreshToken } from '@/utils/auth'; |
| | | import { isURL, validatenull } from '@/utils/validate'; |
| | | import { ElMessage } from 'element-plus'; |
| | | import website from '@/config/website'; |
| | | import NProgress from 'nprogress'; // progress bar |
| | | import 'nprogress/nprogress.css'; // progress bar style |
| | | import { |
| | | Base64 |
| | | } from 'js-base64'; |
| | | import { |
| | | baseUrl |
| | | } from '@/config/env'; |
| | | import { Base64 } from 'js-base64'; |
| | | import { baseUrl } from '@/config/env'; |
| | | import crypto from '@/utils/crypto'; |
| | | const adminUrl = import.meta.env.VITE_APP_DASHBOARD_URL |
| | | const adminUrl = import.meta.env.VITE_APP_DASHBOARD_URL; |
| | | // 全局未授权错误提示状态,只提示一次 |
| | | let isErrorShown = false; |
| | | |
| | |
| | | config.url = baseUrl + config.url; |
| | | } |
| | | //安全请求header |
| | | config.headers['areaCode'] = store?.state?.user?.userInfo?.detail?.areaCode |
| | | config.headers['areaCode'] = store?.state?.user?.userInfo?.detail?.areaCode; |
| | | config.headers['Blade-Requested-With'] = 'BladeHttpRequest'; |
| | | //headers判断是否需要 |
| | | const authorization = config.authorization === false; |
| | |
| | | const cryptoData = config.cryptoData === true; |
| | | const token = getToken(); |
| | | if (token && !isToken) { |
| | | config.headers[website.tokenHeader] = cryptoToken ? |
| | | 'crypto ' + crypto.encryptAES(token, crypto.cryptoKey) : |
| | | 'bearer ' + token; |
| | | config.headers[website.tokenHeader] = cryptoToken |
| | | ? 'crypto ' + crypto.encryptAES(token, crypto.cryptoKey) |
| | | : 'bearer ' + token; |
| | | } |
| | | // 开启报文加密 |
| | | // if (cryptoData) { |
| | |
| | | const currentRouteName = router.currentRoute.value.name; |
| | | // 如果当前路由不是登录页,则跳转到登录页 |
| | | if (currentRouteName !== '登录页') { |
| | | store.dispatch('FedLogOut').then(() => router.push({ |
| | | path: '/login' |
| | | })); |
| | | store.dispatch('FedLogOut').then(() => |
| | | router.push({ |
| | | path: '/login', |
| | | }) |
| | | ); |
| | | } |
| | | return Promise.reject(new Error(message)); |
| | | } |
| | |
| | | // 获取刷新后的token |
| | | const token = getToken(); |
| | | if (token && !isToken) { |
| | | config.headers[website.tokenHeader] = cryptoToken ? |
| | | 'crypto ' + crypto.encryptAES(token, crypto.cryptoKey) : |
| | | 'bearer ' + token; |
| | | config.headers[website.tokenHeader] = cryptoToken |
| | | ? 'crypto ' + crypto.encryptAES(token, crypto.cryptoKey) |
| | | : 'bearer ' + token; |
| | | } |
| | | // 重新发送原来的请求 |
| | | return axios(config); |
| | |
| | | // 清除token信息 |
| | | removeToken(); |
| | | removeRefreshToken(); |
| | | const env = import.meta.env.VITE_APP_ENV; |
| | | // 重定向到登录页 |
| | | // store.dispatch('FedLogOut').then(() => router.push({ |
| | | // path: '/login' |
| | | // })); |
| | | store.dispatch('FedLogOut').then(() => window.location.replace(`${adminUrl}#/login`)); |
| | | env === 'development' |
| | | ? store.dispatch('FedLogOut').then(() => |
| | | router.push({ |
| | | path: '/login', |
| | | }) |
| | | ) |
| | | : store.dispatch('FedLogOut').then(() => window.location.replace(`${adminUrl}#/login`)); |
| | | return Promise.reject(new Error(message)); |
| | | }); |
| | | } |
| | |
| | | // store.dispatch('FedLogOut').then(() => router.push({ |
| | | // path: '/login' |
| | | // })); |
| | | store.dispatch('FedLogOut').then(() => window.location.replace(`${adminUrl}#/login`)); |
| | | const env = import.meta.env.VITE_APP_ENV; |
| | | env === 'development' |
| | | ? store.dispatch('FedLogOut').then(() => |
| | | router.push({ |
| | | path: '/login', |
| | | }) |
| | | ) |
| | | : store.dispatch('FedLogOut').then(() => window.location.replace(`${adminUrl}#/login`)); |
| | | return Promise.reject(new Error(message)); |
| | | } |
| | | // 如果请求为oauth2错误码则首次报错时提示 |