import axios from 'axios'

const service = axios.create({
    baseURL: '',
    timeout: 120000
})

// 请求拦截器
service.interceptors.request.use(config => {
    const token = localStorage.getItem('token');
    if (token) {
        config.headers.Authorization = `${token}`;
    }
    return config;
}, error => {
    return Promise.reject(error);
});

export async function request(config) {
    try {
        const res = await service(config)
        if (res === null || res === undefined) {
            return res
        }
        if (Object.prototype.hasOwnProperty.call(res, 'data')) {
            return res.data
        }
    } catch (error) {
        console.log(error)
        return null
    }
}