http.js
4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import axios from 'axios'
import qs from 'qs'
export default {
post(url, data,params) {
return axios({
method: 'POST', // 请求协议
url: url, // 请求的地址
data: data, // post 请求的实体类数据
params: params, //urlencoded 参数
timeout: 30000, // 超时时间, 单位毫秒
headers: {
'Content-Type': 'application/json;charset=UTF-8',
}
})
},
postToDify(url, data, token) {
return axios({
method: 'POST', // 请求协议
url: url, // 请求的地址
data: data, // post 请求的实体类数据
timeout: 30000, // 超时时间, 单位毫秒
headers: {
'Content-Type': 'application/json;charset=UTF-8',
'Authorization':'Bearer '+token
}
})
},
postWithFrom(url, data) {
return axios({
method: 'POST', // 请求协议
url: url, // 请求的地址
params: data, // post 请求的数据
timeout: 30000, // 超时时间, 单位毫秒
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
}
})
},
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
}],
})
},
postMulData(url, data) {
return axios({
method: 'POST', // 请求协议
url: url, // 请求的地址
data: data, // post 请求的数据
headers: {
'Content-Type': 'multipart/form-data'
}
})
},
postExcelData(url, data) {
return axios({
method: 'POST', // 请求协议
url: url, // 请求的地址
data: data, // post 请求的数据
headers: {
'Content-Type': 'multipart/form-data'
}
})
},
get(url, params) {
return axios({
method: 'GET',
url: url,
params: params,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
});
},
getStream(url, params) {
return axios({
method: 'GET',
url: url,
responseType: 'blob',
params: params,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
});
},
getPDF(url, params) {
return axios({
method: 'GET',
url: url,
responseType: 'blob',
params: params,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
});
},
put(url, params){
return axios({
method: 'PUT',
url: url,
data: params,
headers: {
'Content-Type': 'application/json;charset=UTF-8'
}
})
},
del: (url,params) => {
return axios({
method: 'DELETE',
url: url,
data: params,
headers: {
'Content-Type': 'application/json;charset=UTF-8'
}
})
},
delByParam: (url,params) => {
return axios({
method: 'DELETE',
url: url,
params: params,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
},
login: data =>{
return axios({
method: 'POST', // 请求协议
url: 'cloud-user-center/login', // 请求的地址
// url: 'cloud-kako-user-center/login', // 请求的地址
data: qs.stringify(data), // post 请求的数据
timeout: 30000, // 超时时间, 单位毫秒
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
}
}
// {
// // 服务器提供的响应
// data: {},
// // 服务器响应的HTTP状态代码
// status: 200,
// // 服务器响应的HTTP状态消息
// statusText: 'OK',
// // 服务器响应头
// headers: {},
// // axios 的配置
// config: {}
// }