import axios from 'axios'
// 创建一个 axios 实例
const service = axios.create({
    baseURL:"http://192.168.2.107:8080",
    timeout:5000,
    headers:{
        'Content-Type':'application/x-www-form-urlencoded;charset=utf-8'
    },
    withCredentials:true

})

// 请求拦截
service.interceptors.request.use((config)=>{
    config.headers=config.headers || {}
    if(localStorage.getItem('token')){
        config.headers.token=localStorage.getItem('token') || ""
    }
    return config
})

// 相应拦截
service.interceptors.response.use((res) => {
    
    const status:number = res.data.status
    if(status!=200){
        //  console.log("dddd");
        //  ElMessage.error(res.data.message)
        //  return Promise.reject(res.data)
        
    }
    return res
},(err)=>{
    // ElMessage.error(err);
})

export default service