|
@@ -0,0 +1,41 @@
|
|
1
|
+import axios from 'axios'
|
|
2
|
+import { Message } from 'element-ui'
|
|
3
|
+import qs from 'qs'
|
|
4
|
+
|
|
5
|
+const Axios = axios.create({
|
|
6
|
+ timeout: 60000,
|
|
7
|
+ responseType: 'json',
|
|
8
|
+ withCredentials: true,
|
|
9
|
+ headers: {}
|
|
10
|
+})
|
|
11
|
+
|
|
12
|
+Axios.interceptors.request.use((config) => {
|
|
13
|
+ config.data = qs.stringify(config.data)
|
|
14
|
+ return config
|
|
15
|
+}, (error) => {
|
|
16
|
+ console.log(error)
|
|
17
|
+})
|
|
18
|
+
|
|
19
|
+Axios.interceptors.response.use((res) => {
|
|
20
|
+ if (res.data.code === 1) {
|
|
21
|
+ return res
|
|
22
|
+ } else if (res.data.code === 2) {
|
|
23
|
+ Message({
|
|
24
|
+ message: res.data.message,
|
|
25
|
+ position: 'bottom',
|
|
26
|
+ duration: 2000
|
|
27
|
+ })
|
|
28
|
+ return res.data.code
|
|
29
|
+ } else if (res.data.code === 0) {
|
|
30
|
+ Message({
|
|
31
|
+ message: res.data.message,
|
|
32
|
+ position: 'bottom',
|
|
33
|
+ duration: 2000
|
|
34
|
+ })
|
|
35
|
+ return res.data.code
|
|
36
|
+ }
|
|
37
|
+}, (error) => {
|
|
38
|
+ console.log(error)
|
|
39
|
+})
|
|
40
|
+
|
|
41
|
+export default Axios
|