diff --git a/src/resources/store/modules/topMenu.js b/src/resources/store/modules/topMenu.js index 201382ee3f1373d89f36d56cc39e0a425039fd27..b9844364625e82b71a2e93240f60bc1961573f49 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 7ab8a7eb933e5b8df79dabee0faace485ce2b5ac..d6ecbdc4d2da5b506d653a09c97ac84a4b7682da 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;