/****   http.js   ****/
// 导入封装好的axios实例
import request from './request'
import upload from './upload'

const http = {
        /**
         * methods: 请求
         * @param url 请求地址 
         * @param params 请求参数
         */
        get(url, params) {
            const config = {
                method: 'get',
                url: url
            }
            if (params) config.params = params
            return request(config)
        },
        post(url, params) {
            const config = {
                method: 'post',
                url: url
            }
            if (params) config.data = params
            return request(config)
        },
        put(url, params) {
            const config = {
                method: 'put',
                url: url
            }
            if (params) config.data = params
            return request(config)
        },
        delete(url, params) {
            const config = {
                method: 'delete',
                url: url
            }
            if (params) config.params = params
            return request(config)
        },
        upload(url, params, type, progress) {
            const config = {
                headers: {
                    'Content-Type': type
                },
                transformRequest: [function(data) {
                    return data
                }],
                onUploadProgress: progressEvent => {
                    let persent = (progressEvent.loaded / progressEvent.total * 100 | 0);
                    progress(persent);
                }
            }
            return upload(url, params, config)
        }
    }
    //导出
export default http