This commit is contained in:
lcw
2025-06-08 22:19:02 +08:00
parent 13603503cc
commit 77819f1bed
4 changed files with 86 additions and 67 deletions

View File

@ -471,7 +471,17 @@ export const publicRoutes = [
const router = createRouter({
history: createWebHashHistory(),
routes: publicRoutes
routes: [...publicRoutes, ...privateRoutes]
});
// 添加路由守卫
router.beforeEach((to, from, next) => {
const token = store.getters.token;
if (!token && to.path !== '/login') {
next('/login');
} else {
next();
}
});
//初始化路由表
export function resetRouter() {

View File

@ -14,11 +14,11 @@ service.interceptors.request.use(
// 请求接口之前 做些什么
//1.统一注入token
if (store.getters.token) {
// if (isCheckTimeout()) {
// //超时 执行退出
// store.dispatch('user/logout');
// return Promise.reject(new Error('token 失效'));
// }
if (isCheckTimeout()) {
//超时 执行退出
store.dispatch('user/logout');
return Promise.reject(new Error('token 失效'));
}
if (!config.url.startsWith("/jcApi")) {
config.headers.Authorization = `${store.getters.token}`;
}