PublicAxiosInstance.js 921 Bytes
import axios from 'axios'
import router from '@/router/index'
import Cookies from "js-cookie"
import {getTimestampString} from "@/PublicUtil/PublicUtil"

// 创建 axios 的一个实例
const axiosInstance = axios.create(
    {
        baseURL: window._baseUrl
    }
)

// 请求拦截器
axiosInstance.interceptors.request.use(
    config => {
        if (['localhost', '192.168.1.104'].includes(window.location.hostname))
        {
            config.headers.Authorization = 'a54766a2-96df-43cf-ab78-963a8b7915de'
        }
        else
        {
            config.headers.Authorization = Cookies.get('atoken')
        }

        return config
    }
)

// 响应拦截器
axiosInstance.interceptors.response.use(
    (r) => {
        const responseData = r.data

        return responseData
    },
    (e) => {
        const responseData = e.response

        return responseData
    }
)

export default axiosInstance