审查视图

src/api/http.js 3.9 KB
朱兆平 authored
1
import axios from 'axios'
2 3
import qs from 'qs'
朱兆平 authored
4
export default {
5
    post(url, data,params) {
朱兆平 authored
6
        return axios({
7
            method: 'POST', // 请求协议
朱兆平 authored
8
            url: url, // 请求的地址
9
            data: data, // post 请求的数据
10
            params: params,
朱兆平 authored
11 12
            timeout: 30000, // 超时时间, 单位毫秒
            headers: {
13
                'Content-Type': 'application/json;charset=UTF-8',
朱兆平 authored
14 15 16
            }
        })
    },
17 18 19 20 21 22 23 24 25 26
    postWithFrom(url, data) {
            return axios({
                method: 'POST', // 请求协议
                url: url, // 请求的地址
                params: data, // post 请求的数据
                timeout: 30000, // 超时时间, 单位毫秒
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                }
            })
朱兆平 authored
27 28 29 30 31 32 33 34 35 36 37 38 39 40
    },
    postFormData(url, data) {
            return axios({
                method: 'POST', // 请求协议
                url: url, // 请求的地址
                data: data, // post 请求的数据
                timeout: 30000, // 超时时间, 单位毫秒
                transformRequest: [function(data, headers) {
                      // 去除post请求默认的Content-Type
                      delete headers.post['Content-Type']
                      return data
                    }],
                })
    },
41 42 43 44 45 46 47 48 49 50
    postMulData(url, data) {
        return axios({
            method: 'POST', // 请求协议
            url: url, // 请求的地址
            data: data, // post 请求的数据
            headers: {
                'Content-Type': 'multipart/form-data'
            }
        })
    },
xudada authored
51 52 53 54 55 56 57 58 59 60
    postExcelData(url, data) {
        return axios({
            method: 'POST', // 请求协议
            url: url, // 请求的地址
            data: data, // post 请求的数据
            headers: {
                'Content-Type': 'multipart/form-data'
            }
        })
    },
朱兆平 authored
61
    get(url, params) {
62 63 64
        return axios({
            method: 'GET',
            url: url,
65
            params:  params,
66
            headers: {
shenhailong authored
67
                'Content-Type': 'application/x-www-form-urlencoded'
68 69
            }
        });
朱兆平 authored
70
    },
xudada authored
71 72 73 74
    getStream(url, params) {
        return axios({
            method: 'GET',
            url: url,
75
            responseType: 'blob',
xudada authored
76 77 78 79 80 81
            params:  params,
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        });
    },
朱兆平 authored
82 83 84
    put(url, params){
        return axios({
            method: 'PUT',
85
            url: url,
朱兆平 authored
86 87 88 89 90 91 92 93 94
            data: params,
            headers: {
                'Content-Type': 'application/json;charset=UTF-8'
            }
        })
    },
    del: (url,params) => {
        return axios({
            method: 'DELETE',
95
            url: url,
朱兆平 authored
96 97 98 99 100
            data: params,
            headers: {
                'Content-Type': 'application/json;charset=UTF-8'
            }
        })
101
    },
102 103 104 105 106 107 108 109 110 111
    delByParam: (url,params) => {
        return axios({
            method: 'DELETE',
            url: url,
            params: params,
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        })
    },
112 113 114
    login: data =>{
        return axios({
            method: 'POST', // 请求协议
115 116
            url: 'cloud-user-center/login', // 请求的地址
            // url: 'cloud-kako-user-center/login', // 请求的地址
117 118 119
            data: qs.stringify(data), // post 请求的数据
            timeout: 30000, // 超时时间, 单位毫秒
            headers: {
120
                'Content-Type': 'application/x-www-form-urlencoded'
121 122
            }
        })
朱兆平 authored
123 124 125 126 127 128 129 130 131 132 133 134 135 136
    }
}

// {
//     // 服务器提供的响应
//     data: {},
//     // 服务器响应的HTTP状态代码
//     status: 200,
//         // 服务器响应的HTTP状态消息
//         statusText: 'OK',
//     // 服务器响应头
//     headers: {},
//     // axios 的配置
//     config: {}
137
// }