whyczyk
2022-06-09 11be4fa888dcbb55bbf43b6caf1f4a4abd16a208
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
import Vue from 'vue';
import axios from 'axios';
import store from '@/store'
import rejectReplay from "@/assets/js/tools/rejectReplay";
if (process.env.NODE_ENV == 'dev') {
    // 跨域请求
    axios.defaults.baseURL = 'http://localhost:8090/screen';
    axios.defaults.withCredentials = true; // 保持请求头
} else {
    axios.defaults.baseURL = '/screen';
    axios.defaults.withCredentials = true; // 保持请求头
}
let skipUrls = ["Server_stateAction_action_getTimestamp"];
// 添加请求拦截器
axios.interceptors.request.use(function (config) {
    if (config.asy) {
        if (process.env.NODE_ENV == 'dev') {
            config.baseURL = 'http://localhost:8919/fg';
        } else {
            config.baseURL = `http://${location.hostname}:8919/fg`;
        }
        config.withCredentials = true; // 保持请求头
        // if (store.state.app.newPlatform != 1) {
        //     // 防重放操作
        //     let rejectReplayStr = rejectReplay();
        //     let url = config.url;
        //     let isIn = false;
        //     for (let i = 0; i < skipUrls.length; i++) {
        //         let skipUrl = skipUrls[i];
        //         if (skipUrl == url) {
        //             isIn = true;
        //             break;
        //         }
        //     }
        //     if (!isIn) {
        //         if (url.indexOf("?") == -1) {
        //             url = url.trim() + "?" + rejectReplayStr;
        //         } else {
        //             url = url.trim() + "&" + rejectReplayStr;
        //         }
        //     }
        //     config.url = url;
        // }
    }
    // 在发送请求之前做些什么
    return config;
}, function (error) {
    // 对请求错误做些什么
    return Promise.reject(error);
});
 
// 添加响应拦截器
axios.interceptors.response.use(function (response) {
    // 对响应数据做点什么
    return response;
}, function (error) {
    return Promise.reject(error);
});
//对POST请求数据做处理
// axios.interceptors.request.use((res) => {
//     if(res.method !== "get" && res.data){
//         debugger
//         res.data = qs.stringify(res.data);
//     }
//     return res;
// });
 
Vue.prototype.$axios = axios;
 
export default axios;