From 806020211c46dbea8a2ef321e78d54fb001057a0 Mon Sep 17 00:00:00 2001
From: gerson <1405270578@qq.com>
Date: 星期四, 04 七月 2024 00:22:48 +0800
Subject: [PATCH] 路由和请求均可唤起登录弹窗

---
 src/router/index.ts |   26 ++++++++++++++++++--------
 1 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/src/router/index.ts b/src/router/index.ts
index 44ff9db..7ce9f91 100644
--- a/src/router/index.ts
+++ b/src/router/index.ts
@@ -1,17 +1,14 @@
-import NProgress from 'nprogress';
 import 'nprogress/nprogress.css';
 import { storeToRefs } from 'pinia';
 import { createRouter, createWebHashHistory } from 'vue-router';
 import { MenuTypeEnum } from '/@/api/menu/type';
-import { initBackEndControlRoutes } from '/@/router/backEnd';
-import { initFrontEndControlRoutes } from '/@/router/frontEnd';
 import { notFoundAndNoPower, staticRoutes } from '/@/router/route';
 import pinia from '/@/stores/index';
 import { useKeepALiveNames } from '/@/stores/keepAliveNames';
-import { useRoutesList } from '/@/stores/routesList';
 import { useThemeConfig } from '/@/stores/themeConfig';
-import { accessSessionKey, clearAccessTokens } from '/@/utils/request';
-import { Local } from '/@/utils/storage';
+import { Local } from '../utils/storage';
+import { accessSessionKey } from '../utils/request';
+import emitter from '../utils/mitt';
 
 /**
  * 1銆佸墠绔帶鍒惰矾鐢辨椂锛歩sRequestRoutes 涓� false锛岄渶瑕佸啓 roles锛岄渶瑕佽蛋 setFilterRoute 鏂规硶銆�
@@ -95,8 +92,21 @@
 }
 
 // 璺敱鍔犺浇鍓�
-
-
+router.beforeEach((to, from, next) => {
+	const accessSession = Local.get(accessSessionKey);
+	if (!accessSession) {
+		emitter.emit('openLoginDlg');
+		if(to.name==='Home'){
+			next();
+		}else{
+			next({
+				name: 'Home',
+			});
+		}
+		
+	}
+	next();
+});
 // 璺敱鍔犺浇鍚�
 
 // 瀵煎嚭璺敱

--
Gitblit v1.9.3