request.js
1.43 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
const Axios = axios.create({
baseURL: window._CONF_.apiUrl,
timeout: 0,
withCredentials: true,
headers: {
"Content-Type": "application/json;charset=UTF-8"
}
})
Axios.interceptors.request.use(
config => {
// const atoken = Cookies.get('atoken')
// console.log('atoken', atoken)
// atoken && (config.headers.Authorization = atoken)
return config
},
error => {
return Promise.reject(error)
}
)
Axios.interceptors.response.use(
res => {
// if (res.data.enote || res.data.code === 401) {
// ELEMENT.MessageBox.alert('授权到期, 请重新登录', '提示', {
// confirmButtonText: '确定',
// callback: action => {
// console.log('action', action)
// window.location.replace(window.location.href + 'login.html')
// }
// });
// } else {
return Promise.resolve(res.data)
// }
},
error => {
console.error(error)
return Promise.reject(error)
}
)
function get(url, params = {}, config = {}) {
params['s'] = +new Date()
return Axios.get(url, {...config, params})
}
function post(url, params, config = {}) {
return Axios.post(url, params, config)
}
function deletes(url, params, config = {}) {
return Axios.delete(url, params, config)
}
function put(url, params, config = {}) {
return Axios.put(url, params, config)
}