Explorar o código

fix: 修复C大脑单点登录路由不拦截的问题

ai0197 hai 2 meses
pai
achega
bbf2a71edb

+ 3 - 0
src/enums/pageEnum.ts

@@ -6,6 +6,9 @@ export enum PageEnum {
   REDIRECT = '/redirect',
   REDIRECT_NAME = 'Redirect',
 
+  // C大脑登录
+  C_BRAIN_ENTRY = '/cbrain-entry',
+
   ROOT = '/',
   // 首页
   BASE_HOME = '/home',

+ 0 - 14
src/router/base.ts

@@ -1,6 +1,5 @@
 import type { AppRouteRecordRaw } from '@/router/types';
 import { ErrorPage, RedirectName, Layout } from '@/router/constant';
-import { checkCBrainOAuthToken } from '@/utils/checkCBrainOAuth';
 
 // 404 on a page
 export const ErrorPageRoute: AppRouteRecordRaw = {
@@ -44,16 +43,3 @@ export const RedirectRoute: AppRouteRecordRaw = {
     },
   ],
 };
-
-/** C大脑 OAuth2.0 单点登录入口(无 code 会重定向到授权页,有 code 会换 token 后跳首页) */
-export const CbrainEntryRoute: AppRouteRecordRaw = {
-  path: '/cbrain-entry',
-  name: 'cbrain-entry',
-  component: () => import('@/views/entry/Entry.vue'),
-  beforeEnter: (to, from, next) => {
-    checkCBrainOAuthToken(to, from, next);
-  },
-  meta: {
-    title: 'C大脑登录',
-  },
-};

+ 16 - 2
src/router/full-routes.ts

@@ -16,8 +16,9 @@ import {
   trafficRoutes,
   securityConfidentialityRoutes,
   campusRoutes,
-  productionSafetyRoutes
+  productionSafetyRoutes,
 } from './routers';
+import { checkCBrainOAuthToken } from '@/utils/checkCBrainOAuth';
 
 export type RouteRecordString = Omit<AppRouteRecordRaw, 'component'> & { component?: string };
 
@@ -41,6 +42,19 @@ export const HOME_PAGE: RouteRecordString = {
   },
 };
 
+/** C大脑 OAuth2.0 单点登录入口(无 code 会重定向到授权页,有 code 会换 token 后跳首页) */
+export const CbrainEntryRoute: RouteRecordString = {
+  path: '/cbrain-entry',
+  name: 'cbrain-entry',
+  component: '/entry/Entry',
+  beforeEnter: (to, from, next) => {
+    checkCBrainOAuthToken(to, from, next);
+  },
+  meta: {
+    title: 'C大脑登录',
+  },
+};
+
 export const fullRoutes: AppRouteRecordRaw[] = [
   disasterPreventionRoute,
   emergencyManagementRoute,
@@ -49,7 +63,7 @@ export const fullRoutes: AppRouteRecordRaw[] = [
   trafficRoutes,
   securityConfidentialityRoutes,
   campusRoutes,
-  productionSafetyRoutes
+  productionSafetyRoutes,
 ] as const;
 
 /**

+ 1 - 0
src/router/generator-routers.ts

@@ -29,6 +29,7 @@ export const routerGenerator = (routerMap, parent?): any[] => {
       // 该路由对应页面的 组件
       component: item.component,
       // meta: 页面标题, 菜单图标, 页面权限(供指令权限用,可去掉)
+      beforeEnter: item.beforeEnter,
       meta: {
         ...item.meta,
         label: item.meta.title,

+ 2 - 2
src/router/index.ts

@@ -1,9 +1,9 @@
 import { App } from 'vue';
 import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';
-import { RedirectRoute, CbrainEntryRoute } from '@/router/base';
+import { RedirectRoute } from '@/router/base';
 import { createRouterGuards } from './router-guards';
 import { exceptionRouters } from './routers';
-import { HOME_PAGE, RootRoute } from './full-routes';
+import { HOME_PAGE, RootRoute, CbrainEntryRoute } from './full-routes';
 import { asyncImportRoute, routerGenerator } from './generator-routers';
 
 const routeModuleList: RouteRecordRaw[] = [];

+ 1 - 1
src/router/router-guards.ts

@@ -12,7 +12,7 @@ import { getRedirectUrl } from '@/utils/getRedirectUrl';
 
 const LOGIN_PATH = PageEnum.BASE_LOGIN;
 
-const whitePathList = [LOGIN_PATH, PageEnum.ROOT, PageEnum.BASE_HOME]; // no redirect whitelist
+const whitePathList = [LOGIN_PATH, PageEnum.ROOT, PageEnum.BASE_HOME, PageEnum.C_BRAIN_ENTRY]; // no redirect whitelist
 
 const setDynamicRoute = async (router) => {
   const userStore = useUserStoreWidthOut();