| | |
| | | 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 crypto from '@/utils/crypto'; |
| | |
| | | }; |
| | | //跨域请求,允许保存cookie |
| | | axios.defaults.withCredentials = true; |
| | | // NProgress Configuration |
| | | NProgress.configure({ |
| | | showSpinner: false, |
| | | }); |
| | | |
| | | //http request拦截 |
| | | axios.interceptors.request.use( |
| | | config => { |
| | | // start progress bar |
| | | NProgress.start(); |
| | | // 初始化错误提示状态 |
| | | isErrorShown = false; |
| | | //地址为已经配置状态则不添加前缀 |
| | |
| | | config.url = baseUrl + config.url; |
| | | } |
| | | //安全请求header |
| | | config.headers['areaCode'] = store?.state?.user?.userInfo?.detail?.areaCode; |
| | | config.headers['areaCode'] = config?.params?.areaCode || store?.state?.user?.userInfo?.detail?.areaCode; |
| | | config.headers['Blade-Requested-With'] = 'BladeHttpRequest'; |
| | | //headers判断是否需要 |
| | | const authorization = config.authorization === false; |
| | |
| | | `${website.clientId}:${website.clientSecret}` |
| | | )}`; |
| | | } |
| | | // 后端的要求 |
| | | if (router.currentRoute.value.path === '/job/jobstatistics'){ |
| | | const userAreaCode = store?.state?.user?.userInfo?.detail?.areaCode |
| | | const paramsKey = config.method === 'get' ? 'params' : 'data'; |
| | | const codeKey = config.method === 'get' ? 'areaCode' : 'area_code'; |
| | | const paramCode = config?.params?.areaCode || config?.data?.area_code |
| | | try { |
| | | if (paramCode){ |
| | | if (paramCode === userAreaCode) { |
| | | config[paramsKey][codeKey] = config.method === 'get' ? '' : undefined; |
| | | } else { |
| | | if (!Array.isArray(config[paramsKey])){ |
| | | config[paramsKey] = {...config[paramsKey],[codeKey]: paramCode} |
| | | } |
| | | } |
| | | } |
| | | }catch (e) {} |
| | | } |
| | | |
| | | //headers判断请求是否携带token |
| | | const meta = config.meta || {}; |
| | | const isToken = meta.isToken === false; |
| | |
| | | //http response拦截 |
| | | axios.interceptors.response.use( |
| | | res => { |
| | | NProgress.done(); |
| | | const status = res.data.error_code || res.data.code || res.status; |
| | | const statusWhiteList = website.statusWhiteList || []; |
| | | const message = res.data.msg || res.data.error_description || res.data.message || '系统错误'; |
| | |
| | | return res; |
| | | }, |
| | | error => { |
| | | NProgress.done(); |
| | | return Promise.reject(new Error(error)); |
| | | } |
| | | ); |