From 400c96d9d20cc5c6789d7f8f8140336425e2244c Mon Sep 17 00:00:00 2001 From: tinyu Date: Thu, 28 Mar 2024 11:27:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E8=B0=83=E6=95=B4=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/layout/index.vue | 37 +++++++++++++++++---------------- src/utils/index.js | 13 ++++++++++++ src/utils/modules/routeUtils.js | 16 ++++++++++++++ 3 files changed, 48 insertions(+), 18 deletions(-) diff --git a/src/components/layout/index.vue b/src/components/layout/index.vue index 7a7a06b..5ca4f11 100644 --- a/src/components/layout/index.vue +++ b/src/components/layout/index.vue @@ -3,39 +3,39 @@ - \ No newline at end of file diff --git a/src/utils/index.js b/src/utils/index.js index e69de29..9ec9215 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -0,0 +1,13 @@ +// directory 是要搜索的目录 , useSubdirectories 表示是否搜索子目录, regExp 是匹配文件的正则表达式 +const context = require.context('./modules', false, /.js$/) +// 讲所有模块导出内容添加到_obj中 +const _obj = context.keys().reduce((pre, key) => { + const name = key.replace(/.\/|.js/g,'') + const module=context(key); + Object.entries(module).forEach(([attr,value])=> { + pre[attr] = value; + }) + return pre; +},{}) + +export default _obj \ No newline at end of file diff --git a/src/utils/modules/routeUtils.js b/src/utils/modules/routeUtils.js index e69de29..60d92e1 100644 --- a/src/utils/modules/routeUtils.js +++ b/src/utils/modules/routeUtils.js @@ -0,0 +1,16 @@ +/** + * + * @param {Array} list 路由数据 + * @param {Function} processFn 处理函数 + * @returns {Array} 数组数据 + */ +export function coventRouteData(list, processFn) { + return list.map(item => { + let { children, component, ...rest } = item; + if (children && Array.isArray(children)) { + children = coventRouteData(children, processFn) + return processFn({ children, ...rest }) + } + return processFn(rest) + }); +} -- GitLab