import service from './Axios'
import qs from "qs";


// json格式请求头
const headerJSON = {
    "Content-Type": "application/json;charset=UTF-8",
    'internetGatewaySource':'internetGwSourceExt'
};
// FormData格式请求头
const headerFormData = {
    "Content-Type": "application/x-www-form-urlencoded",
    'internetGatewaySource':'internetGwSourceExt'
};


const http = {
    /**
 * methods: 请求
 * @param url 请求地址
 * @param params 请求参数
 * @param json 判断数据发送是否是json格式: true-为是  false-为否
 */
    get(url, params, json, authorization) {
        if (authorization) {
            headerJSON['authorization'] = authorization
        }
        const config = {
            method: "get",
            url: url,
            headers: json ? headerJSON : headerFormData
        };
        if (params) config.params = params;
        return service(config);
    },
    post(url, params, json, authorization) {

        if (authorization) {
            headerJSON['authorization'] = authorization
        }

        const config = {
            method: "post",
            url: url,
            headers: json ? headerJSON : headerFormData
        };

        if (params) config.data = json ? params : qs.stringify(params);

        return service(config);
    },
    put(url, params, json) {
        const config = {
            method: "put",
            url: url,
            headers: headerFormData
        };
        if (params) config.params = params;
        return service(config);
    },
    delete(url, params, json) {
        const config = {
            method: "delete",
            url: url,
            headers: headerFormData
        };
        if (params) config.params = params;
        return service(config);
    },

}


//导出
export default http;