From 6465dd7ce3ce715a7d395f6c0f071aeb3d655e52 Mon Sep 17 00:00:00 2001 From: buaixuexideshitongxue <2936013465@qq.com> Date: Tue, 3 Feb 2026 19:45:24 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=AE=E5=BD=95=E8=B0=83=E6=95=B4--=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=B7=BB=E5=8A=A0=E5=A4=96=E9=93=BE=E8=8F=9C=E5=8D=95?= =?UTF-8?q?--=E5=9B=9E=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/permission.ts | 20 +++++--------------- src/router/index.ts | 27 +++++++-------------------- 2 files changed, 12 insertions(+), 35 deletions(-) diff --git a/src/permission.ts b/src/permission.ts index 006266c..7584ebb 100644 --- a/src/permission.ts +++ b/src/permission.ts @@ -40,24 +40,14 @@ router.beforeEach(async (to, from, next) => { router.addRoute(INDEX_ROUTE) routes.forEach((route: any) => { // 动态添加可访问路由表 - try { - if (!route) { + if (!route.children) { + if (route.meta.type === MenuEnum.CATALOGUE) { return } - if (!route.path || !route.name) { - return - } - if (!route.children) { - if (route.meta?.type === MenuEnum.CATALOGUE) { - return - } - router.addRoute(INDEX_ROUTE_NAME, route) - return - } - router.addRoute(route) - } catch (error) { - console.error('添加路由失败:', error) + router.addRoute(INDEX_ROUTE_NAME, route) + return } + router.addRoute(route) }) next({ ...to, replace: true }) return diff --git a/src/router/index.ts b/src/router/index.ts index 7df566c..d565c51 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -12,21 +12,18 @@ export function getModulesKey() { } export function createRouteRecord(menus) { - // 过滤掉null或undefined的菜单项 - const validMenus = menus.filter(menu => menu != null) - - return validMenus.map(menu => { + return menus.map(menu => { const routeRecord: RouteRecordRaw = { - path: menu.paths || '/', - name: Symbol(menu.paths || Math.random().toString()), + path: menu.paths, + name: Symbol(menu.paths), meta: { hidden: !menu.isShow, keepAlive: !!menu.isCache, - title: menu.menuName || '', + title: menu.menuName, perms: menu.perms, icon: menu.icon, type: menu.menuType, - openOutside: menu.openOutside, + openOutside:menu.openOutside, openNewPage: menu.openNewPage } } @@ -35,13 +32,10 @@ export function createRouteRecord(menus) { routeRecord.component = LAYOUT break case MenuEnum.MENU: - routeRecord.component = loadRouteView(menu.component || '') - break - default: - routeRecord.component = RouterView + routeRecord.component = loadRouteView(menu.component) break } - if (menu.children && menu.children.length) { + if (menu.children.length) { routeRecord.children = createRouteRecord(menu.children) } return routeRecord @@ -51,13 +45,6 @@ export function createRouteRecord(menus) { // 动态加载组件 function loadRouteView(component: string) { try { - // 检查是否是URL类型的组件路径 - if (component.startsWith('http://') || component.startsWith('https://')) { - // 对于URL类型的组件,返回RouterView作为占位符 - // 实际的URL打开会通过openOutside或openNewPage处理 - return RouterView - } - const key = Object.keys(modules).find((key) => { return key.includes(`${component}.vue`) })