diff --git a/src/router/index.js b/src/router/index.js index c997889..2c19462 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -1,4 +1,5 @@ import { createRouter, createWebHashHistory } from 'vue-router'; +import axios from "axios"; const router = createRouter({ history: createWebHashHistory(), @@ -81,6 +82,24 @@ const router = createRouter({ }); +// 全局拦截器 token 过期拦截 +axios.interceptors.response.use( + response => response, + error => { + if (error.response && error.response.status === 401) { + // 清除本地存储的token + localStorage.removeItem('token'); + // 跳转到登录页 + router.push({ + name: 'login', + query: { machineId: localStorage.getItem('machineId'), expired: true } + }); + } + return Promise.reject(error); + } +); + + router.beforeEach((to, from, next) => { const token = localStorage.getItem("token"); const machineId = localStorage.getItem("machineId"); diff --git a/src/views/usergold/clientCountBalance.vue b/src/views/usergold/clientCountBalance.vue index 349a130..4c7515b 100644 --- a/src/views/usergold/clientCountBalance.vue +++ b/src/views/usergold/clientCountBalance.vue @@ -320,7 +320,7 @@ const exportExcel = async function () { - +