From 96ad11c8cc8083da607982d93a8f0ed8fefe64df Mon Sep 17 00:00:00 2001 From: dai <851733175@qq.com> Date: Thu, 17 Nov 2022 10:49:57 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9D=A2=E5=8C=85=E5=B1=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.js | 20 +++++++++++++++++++- src/views/main-content.vue | 28 ++++++++++++++++++++++------ src/views/main-navbar.vue | 2 ++ 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index eca051a0d..dadf71331 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -169,6 +169,22 @@ function cookApiDataItem2(item) { } return item; } +// 把父级拼到子集 +function cookApiDataItem3(item, parent = []) { + item.parent = parent; + let { children } = item; + if (children && Array.isArray(children) && children.length > 0) { + item.children = children.map((val) => + cookApiDataItem3(val, [ + ...parent, + { + title: item.name || "", + }, + ]) + ); + } + return item; +} // 模块路由(基于主入口布局页面) 可视化数据 export const moduleShujuRoutes = { @@ -176,7 +192,7 @@ export const moduleShujuRoutes = { component: () => import("@/views/main-shuju/main"), name: "main-shuju", redirect: { - path:"/main-shuju/visual-basicinfo-basicInfoMain", + path: "/main-shuju/visual-basicinfo-basicInfoMain", }, meta: { title: "主入口布局", @@ -314,6 +330,7 @@ router.beforeEach((to, from, next) => { }); } window.SITE_CONFIG["menuList"] = res.data + .map((item) => cookApiDataItem3(item)) .map((item) => cookApiDataItem2(item)) .map((item) => cookApiDataItem(item)); fnAddDynamicMenuRoutes(window.SITE_CONFIG["menuList"]); @@ -370,6 +387,7 @@ function fnAddDynamicMenuRoutes(menuList = [], routes = []) { menuId: menuList[i].id, title: menuList[i].name, btns: menuList[i].btns || [], + parent: menuList[i].parent || [], }, }; // eslint-disable-next-line diff --git a/src/views/main-content.vue b/src/views/main-content.vue index 56a425eaa..8cc2f8a25 100644 --- a/src/views/main-content.vue +++ b/src/views/main-content.vue @@ -58,15 +58,21 @@ @@ -312,6 +318,8 @@ export default { diff --git a/src/views/main-navbar.vue b/src/views/main-navbar.vue index 74e1c6a01..6eeebd1d6 100644 --- a/src/views/main-navbar.vue +++ b/src/views/main-navbar.vue @@ -162,6 +162,8 @@ export default { this.$store.state.LevelOneMenuActiveName = menuId; this.$store.state.sidebarActiveSubMenuList = this.$store.state.sidebarMenuList[idx].children || []; + console.log("this.$store.state", this.$store.state); + console.log("this.$route", this.$route); }, changeCustomerName(customerName) { this.customerName =