From 385ac73b09c897676ee3302dce06f2841807c458 Mon Sep 17 00:00:00 2001 From: dengbf Date: Tue, 26 Dec 2023 14:46:38 +0800 Subject: [PATCH] =?UTF-8?q?-=20[=E4=BF=AE=E5=A4=8D]=20=E5=95=86=E4=B8=9A?= =?UTF-8?q?=E7=89=88router=E4=BC=9A=E6=9B=BF=E6=8D=A2=E7=A4=BE=E5=8C=BA?= =?UTF-8?q?=E7=89=88router=EF=BC=8C=E5=AF=BC=E8=87=B4=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E4=B8=8D=E5=87=BA=E6=9D=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/resources/store/modules/topMenu.js | 26 +++++++++++++++++++++++++- src/views/pages/process/router.js | 16 ++-------------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/resources/store/modules/topMenu.js b/src/resources/store/modules/topMenu.js index 201382ee3..b98443646 100644 --- a/src/resources/store/modules/topMenu.js +++ b/src/resources/store/modules/topMenu.js @@ -273,9 +273,33 @@ const actions = { function getRouterConfig() { let routerConfig = {}; let routerPathList = [require.context('@/views/pages', true, /router.js$/)]; + routerPathList.forEach(item => { + if (item && item.keys()) { + item.keys().forEach(routerPath => { + const moduleNames = routerPath.split('/')[1]; + const lastValue = moduleNames.split('-'); + const moduleName = lastValue?.pop() || moduleNames; + const routeList = item(routerPath).default || []; + routerConfig[moduleName] = routeList; + }); + } + }); + let commercialRouterConfig = getCommercialRouter(); + Object.keys(commercialRouterConfig).forEach(key => { + if (routerConfig[key]) { + routerConfig[key].push(...commercialRouterConfig[key]); + } else { + routerConfig[key] = commercialRouterConfig[key]; + } + }); + return routerConfig; +} +function getCommercialRouter() { //商业版模块 + let routerConfig = {}; + let routerPathList = []; try { routerPathList.push(require.context('@/commercial-module', true, /router.js$/)); - } catch (error) { + } catch { // 模块找不到 } routerPathList.forEach(item => { diff --git a/src/views/pages/process/router.js b/src/views/pages/process/router.js index 7ab8a7eb9..d6ecbdc4d 100644 --- a/src/views/pages/process/router.js +++ b/src/views/pages/process/router.js @@ -350,17 +350,5 @@ let routerList = [ } } ]; -let importRouterList = []; -try { - // 导入自定义路由 - const routerContext = require.context('@/commercial-module', true, /router.js$/); - routerContext.keys().forEach(filePath => { - const moduleName = filePath?.split('/')[1]?.split('-')?.pop() || filePath?.split('/')[1]; - if (moduleName && config?.module && moduleName == config.module) { - importRouterList = routerContext(filePath).default || []; - } - }); -} catch (error) { - // 捕获异常 -} -export default [...routerList, ...importRouterList]; + +export default routerList; -- Gitee