whyczyk
2022-03-02 733823ffa701f749c7154cacf60a26951891f2ca
src/assets/js/axios.js
@@ -1,7 +1,7 @@
import Vue from 'vue';
import axios from 'axios';
import store from '@/store'
// import qs from 'qs';
import rejectReplay from "@/assets/js/tools/rejectReplay";
if (process.env.NODE_ENV == 'dev') {
    // 跨域请求
    axios.defaults.baseURL = 'http://localhost:8090/screen';
@@ -10,6 +10,7 @@
    axios.defaults.baseURL = '/screen';
    axios.defaults.withCredentials = true; // 保持请求头
}
let skipUrls = ["Server_stateAction_action_getTimestamp"];
// 添加请求拦截器
axios.interceptors.request.use(function (config) {
    if (config.asy) {
@@ -27,6 +28,27 @@
            }
        }
        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;