zhouwx
2024-07-08 1ee4a5341215f94128b66cee4893c7c937df509a
src/util/request.js
@@ -10,7 +10,7 @@
const { baseUrl } = require('../../config/env.' + process.env.NODE_ENV)
const http= axios.create({
    baseURL: baseUrl,
    timeout: 5000,//响应时间
    timeout: 50000,//响应时间
    // headers:{"Content-Type":"application/json;charset=utf-8"},
})
@@ -36,42 +36,40 @@
    (response) => {
        // 对响应数据做点什么
        if (response.data.code && response.data.code === 401) {
            message.error('用户不存在');
            loginOut()
                .then(() => {
                    Session.clear();
                    window.location.href = '/';
                });
            // useLoginApi()
            //     .signOut()
            //     .then(() => {
            //         Session.clear();
            //         window.location.href = '/';
            //     });
            // message.error('用户不存在')
            setTimeout(()=>{
                loginOut()
                    .then(() => {
                        Session.clear();
                        window.location.href = '/';
                    });
            },2000)
        } else if (response.data.code && response.data.code === 405) {
            message.error('token失效');
            message.error('token失效')
            setTimeout(()=>{
            loginOut()
                .then(() => {
                    Session.clear();
                    window.location.href = '/';
                });
            },2000)
        }
        return Promise.resolve(response);
    },
    (error) => {
        // 对响应错误做点什么
        if (error.message.indexOf('timeout') != -1) {
            message.error('网络超时');
            setTimeout(() => {
                Session.clear();
                window.location.href = '/';
            }, 1000);
            message.error('网络超时')
            // setTimeout(() => {
            //     Session.clear()
            //     window.location.href = '/'
            // }, 1000)
        } else if (error.message == 'Network Error') {
            message.error('网络连接错误');
            setTimeout(() => {
                Session.clear();
                window.location.href = '/';
            }, 1000);
            message.error('网络连接错误')
            // setTimeout(() => {
            //     Session.clear()
            //     window.location.href = '/'
            // }, 1000)
        } else {
            if (error.response.data) message.error(error.response.data.error);
            else message.error('接口路径找不到');