Admin
2022-08-15 a1d03a0e810219f8353748f6e55699bf2e1a77a6
src/utils/request.ts
@@ -1,7 +1,9 @@
import axios from 'axios';
import { ElMessage, ElMessageBox } from 'element-plus';
import { Session } from '/@/utils/storage';
import JSONbig from 'json-bigint';
import Cookies from 'js-cookie';
import {useLoginApi} from "/@/api/login";
import { Session, } from '/@/utils/storage';
// var jsonBig = require('json-bigint')({ "storeAsString": true });
// 配置新建一个 axios 实例
@@ -18,9 +20,9 @@
                config.data[key] = null;
            }
        }
        if (Session.get('token')) {
            (<any>config.headers).common['Authorization'] = `${Session.get('token')}`;
            (<any>config.headers).common['uid'] = `${Session.get('uid')}`;
        if (Cookies.get('token')) {
            (<any>config.headers).common['Authorization'] = `${Cookies.get('token')}`;
            (<any>config.headers).common['uid'] = `${Cookies.get('uid')}`;
        }
        return config;
    },
@@ -56,10 +58,13 @@
            }, 1000);
        } else if (response.data.code && response.data.code === 'A0215') {
            ElMessage.error('token失效');
            setTimeout(() => {
                Session.clear();
                window.location.href = '/';
            }, 1000);
            // logOut;
            useLoginApi().signOut().then(()=>{
                setTimeout(() => {
                    Session.clear();
                    window.location.href = '/';
                }, 1000);
            })
        }
        // if(response.data.code && response.data.code !== '200'){
        return Promise.resolve(response);
@@ -88,7 +93,7 @@
        if (error.message.indexOf('timeout') != -1) {
            ElMessage.error('网络超时');
            setTimeout(() => {
                Session.clear();
                // Session.clear();
                window.location.href = '/';
            }, 1000);
        } else if (error.message == 'Network Error') {