Prechádzať zdrojové kódy

reactor:单点登录调整;

zhangchong 6 mesiacov pred
rodič
commit
52c5e37ee0
2 zmenil súbory, kde vykonal 22 pridanie a 45 odobranie
  1. 20 40
      src/App.vue
  2. 2 5
      src/router/index.ts

+ 20 - 40
src/App.vue

@@ -124,6 +124,7 @@ onBeforeMount(async () => {
 const router = useRouter();
 // 登录成功后的跳转
 const signInSuccess = (isNoPower: boolean | undefined) => {
+	window.history.replaceState({}, document.title, window.location.pathname);
 	if (isNoPower) {
 		ElNotification({
 			title: '提示',
@@ -133,6 +134,9 @@ const signInSuccess = (isNoPower: boolean | undefined) => {
 		Session.clear();
 		Cookie.clear();
 		Local.clear();
+		setTimeout(()=>{
+			window.location.reload();
+		},2000)
 	} else {
 		router.push('/');
 		// 设置登录成功后的时间问候语
@@ -192,48 +196,24 @@ onMounted(() => {
 			// 获取url特殊参数 实现登录跳转
 			// 单点登录进来的参数
 			const urlParams = new URLSearchParams(window.location.search);
-			const source = urlParams.get('source');
-			const username = urlParams.get('username');
+			const source = urlParams.get('token');
 			// 判断是否是单点登录
-			const isSingleSignOn = source === 'oldhotline' && username;
-			if (isSingleSignOn) {
+			if (source) {
 				Cookie.remove('token');
-				getTokenByUrl({ userName: username })
-					.then(async (res: any) => {
-						//登录
-						// 存储 token 到浏览器缓存
-						Cookie.set('token', res.result);
-						window.history.replaceState({}, document.title, window.location.pathname);
-						if (!themeConfig.value.isRequestRoutes) {
-							// 前端控制路由,2、请注意执行顺序
-							const isNoPower = await initFrontEndControlRoutes();
-							signInSuccess(isNoPower);
-						} else {
-							// 模拟后端控制路由,isRequestRoutes 为 true,则开启后端控制路由
-							// 添加完动态路由,再进行 router 跳转,否则可能报错 No match found for location with path "/"
-							const isNoPower = await initBackEndControlRoutes();
-							// 执行完 initBackEndControlRoutes,再执行 signInSuccess
-							signInSuccess(isNoPower);
-						}
-					})
-					.catch((err) => {
-						const message = err.response.data.message;
-						ElMessageBox.alert(message, '登录失败', {
-							confirmButtonText: '确定',
-							type: 'error',
-							showClose: false,
-							draggable: true,
-							callback: () => {
-								window.history.replaceState({}, document.title, window.location.pathname);
-								// 清除缓存/token等
-								Local.clear();
-								Session.clear();
-								Cookie.clear();
-								// 使用 reload 时,不需要调用 resetRoute() 重置路由
-								window.location.reload();
-							},
-						});
-					});
+				//登录
+				// 存储 token 到浏览器缓存
+				Cookie.set('token', source);
+				if (!themeConfig.value.isRequestRoutes) {
+					// 前端控制路由,2、请注意执行顺序
+					const isNoPower = await initFrontEndControlRoutes();
+					signInSuccess(isNoPower);
+				} else {
+					// 模拟后端控制路由,isRequestRoutes 为 true,则开启后端控制路由
+					// 添加完动态路由,再进行 router 跳转,否则可能报错 No match found for location with path "/"
+					const isNoPower = await initBackEndControlRoutes();
+					// 执行完 initBackEndControlRoutes,再执行 signInSuccess
+					signInSuccess(isNoPower);
+				}
 			}
 		} catch (error) {
 			console.log(error);

+ 2 - 5
src/router/index.ts

@@ -93,10 +93,7 @@ export function formatTwoStageRoutes(arr: any) {
 const whiteList = ['/login', '/forgetPwd']; //称为白名单,意思就是不需要有token,就可以访问到的路径
 // 单点登录进来的参数
 const urlParams = new URLSearchParams(window.location.search);
-const source = urlParams.get('source');
-const username = urlParams.get('username');
-// 判断是否是单点登录
-const isSingleSignOn = source === 'oldhotline' && username;
+const source = urlParams.get('token');
 // 路由加载前
 router.beforeEach(async (to, from, next) => {
 	NProgress.configure({ showSpinner: false });
@@ -129,7 +126,7 @@ router.beforeEach(async (to, from, next) => {
 	} else {
 		// 如果无token
 		// 假如在白名单,则直接放行,不在则直接强制跳转到登录 (如果有特殊单点登录的参数  也不需要跳到登录页  && (!account || !pwd))
-		if (!whiteList.includes(to.path) && !isSingleSignOn) {
+		if (!whiteList.includes(to.path) && !source) {
 			next(`/login?redirect=${to.path}&params=${JSON.stringify(to.query ? to.query : to.params)}`);
 			NProgress.done();
 		} else {