"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const axios_1 = require("axios");
/**
 * 基于Axios框架实现的Http工具
 * @author wufl2019@qq.com
 * @date 2020-06-23
 */
class HttpUtil {
    constructor(_timeout = 5000) {
        this.axios = axios_1.default.create({
            timeout: _timeout
        });
        //默认拦截器
        this.axios.interceptors.response.use((res) => {
            const data = res.data;
            if (res.status === 200) {
                return data;
            }
            return Promise.reject(res);
        });
    }
    /**
     * @desc get请求
     * @param {String} path 请求api路径
     * @param {Object} data 参数对象
     * @param {Object} config 局部配置 {headers: {'X-Custom-Header': 'foobar'}}
     */
    get(url, data = {}, headers = {}) {
        let config = {};
        config['headers'] = headers;
        return this.axios.get(url, Object.assign({ params: data }, config));
    }
}
exports.HttpUtil = HttpUtil;
exports.default = new HttpUtil();
