吉安感知网项目-前端
罗广辉
2026-02-05 49e2713bf3d079867a2d3ca17151072f23a8b135
feat: 跨域配置
1 files modified
26 ■■■■ changed files
applications/mobile-web-view/src/axios.js 26 ●●●● patch | view | raw | blame | history
applications/mobile-web-view/src/axios.js
@@ -9,13 +9,11 @@
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'
@@ -25,7 +23,6 @@
let isErrorShown = false
// 全局锁机制相关变量
window.isRefreshing = false // 标记当前是否正在刷新token
let refreshTokenPromise = null // 刷新token的Promise,避免重复请求
axios.defaults.timeout = 60000
//返回其他状态码
@@ -33,8 +30,7 @@
    return status >= 200 && status <= 500 // 默认的
}
//跨域请求,允许保存cookie
axios.defaults.withCredentials = true
// NProgress Configuration
axios.defaults.withCredentials = false
NProgress.configure({
    showSpinner: false,
})
@@ -42,19 +38,11 @@
//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
@@ -65,8 +53,8 @@
        // 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 || {}