| | |
| | | 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 { getToken, removeRefreshToken, removeToken } from '@/utils/auth' |
| | | import { validatenull } from '@/utils/validate' |
| | | import website from '@/config/website' |
| | | import NProgress from 'nprogress' // progress bar |
| | | import 'nprogress/nprogress.css' // progress bar style |
| | | import { Base64 } from 'js-base64' |
| | | import crypto from '@/utils/crypto' |
| | | import { getStore } from '@/utils/store' |
| | | import { showToast } from 'vant' |
| | |
| | | let isErrorShown = false |
| | | // 全局锁机制相关变量 |
| | | window.isRefreshing = false // 标记当前是否正在刷新token |
| | | let refreshTokenPromise = null // 刷新token的Promise,避免重复请求 |
| | | |
| | | axios.defaults.timeout = 60000 |
| | | //返回其他状态码 |
| | |
| | | return status >= 200 && status <= 500 // 默认的 |
| | | } |
| | | //跨域请求,允许保存cookie |
| | | axios.defaults.withCredentials = true |
| | | // NProgress Configuration |
| | | axios.defaults.withCredentials = false |
| | | NProgress.configure({ |
| | | showSpinner: false, |
| | | }) |
| | |
| | | //http request拦截 |
| | | axios.interceptors.request.use( |
| | | config => { |
| | | const isBase = config.isBase === false |
| | | // start progress bar |
| | | // NProgress.start() |
| | | // 初始化错误提示状态 |
| | | isErrorShown = false |
| | | //地址为已经配置状态则不添加前缀 |
| | | // if (!isBase && !isURL(config.url) && !config.url.startsWith(VITE_APP_API)) { |
| | | // config.url = VITE_APP_API + config.url |
| | | // } |
| | | // config.url = VITE_APP_ENV === 'development' ? config.url : VITE_APP_XT_URL + config.url |
| | | if ( VITE_APP_ENV === 'development'){ |
| | | if (VITE_APP_ENV === 'development') { |
| | | config.url = VITE_APP_API + config.url |
| | | }else{ |
| | | } else { |
| | | config.url = VITE_APP_XT_URL + config.url |
| | | } |
| | | config.headers['areaCode'] = store.state.user.selectedAreaCode |
| | |
| | | // if (!authorization) { |
| | | // config.headers['Authorization'] = `Basic ${Base64.encode(`${website.clientId}:${website.clientSecret}`)}` |
| | | // } |
| | | let authorization = store.state.user.token |
| | | config.headers['Authorization'] = authorization |
| | | |
| | | config.headers['Authorization'] = store.state.user.token |
| | | // 根据后端要求,post的data为空的话传{} |
| | | if (config.method === 'post') { |
| | | config.data = config.data || {} |