diff --git a/src/router/index.js b/src/router/index.js index 9f87613e6..389c3ba4f 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -107,6 +107,35 @@ export const moduleRoutes = { ], }; +// pc端菜单的 如果没有配置 默认的 或者配置了默认的 但没有权限 默认选中第一 +function cookApiDataItem(item) { + function n2one(v) { + let ret = []; + for (let i = 0; i < v.length; i++) { + console.log("xxxxx", v[i]); + ret.push(v[i]); + if (Array.isArray(v[i].children) && v[i].children.length > 0) { + ret.push(...n2one(v[i].children)); + } + } + console.log("aaaa", ret); + debugger; + return ret; + } + + let allChildrenUrl = n2one(item.children) + .filter((i) => i.url != "") + .map((i) => i.url); + console.log("))))))))))))", allChildrenUrl); + + if (item.children.length > 0) { + if (item.url == "" || !allChildrenUrl.find((i) => i.url == item.url)) { + item.url = allChildrenUrl[0]; + } + } + return item; +} + // 模块路由(基于主入口布局页面) 可视化数据 export const moduleShujuRoutes = { path: "/main-shuju", @@ -250,7 +279,9 @@ router.beforeEach((to, from, next) => { name: "login", }); } - window.SITE_CONFIG["menuList"] = res.data; + window.SITE_CONFIG["menuList"] = res.data.map((item) => + cookApiDataItem(item) + ); fnAddDynamicMenuRoutes(window.SITE_CONFIG["menuList"]); // next({ ...to, replace: true }) next({