import axios from 'axios'
import {Message} from 'element-ui'
import router from '@/router'
// import {removeUser} from '@/utils/user'
import {setStorage, getStorage, removeStorage} from '@/utils/storageUtil';


let ERROR_MESSAGE_OPEN = false;

// 创建 axios 实例
const service = axios.create({
    baseURL: '/minghe',
    timeout: 3000000 // 请求超时时间
});

// request拦截器
service.interceptors.request.use(
    config => {
        // config.headers['originType'] = 'intelligence_community';
        // // config.headers['Token'] = JSON.parse(getStorage("DanBaoToken")) ? JSON.parse(getStorage("DanBaoToken")) :'' ;
        // config.headers['UserId'] = JSON.parse(getStorage("isShowUser")) ? JSON.parse(getStorage("danUserId")) : JSON.parse(getStorage('danUsersEmployeeId'));

        return config
    },
    error => {
        //console.log(error);
        return Promise.reject(error);
    });

// response拦截器
service.interceptors.response.use(
    response => {
        const headers = response.headers
        let res = response.data;
        if (headers['content-type'] === 'application/octet-stream') {
            return Promise.resolve(res);
        } else {
            return Promise.resolve(res)
            // if (res && res.code && res.code === 1000 || res.code === 1001) {
            //     // return Promise.resolve(res.data);
            //     return Promise.resolve(res);
            // } else if (res && res.code && res.code === 4011 || res.code === 4010) {
            //     // return Promise.reject(res.msg)
            //     return Promise.reject(res)
            // } 
        }
    },
    error => {
        return Promise.reject(error)
    }
);

export default service
