| | |
| | | const { name, path, parentId, meta } = routeInfo; |
| | | return isAllEmpty(parentId) |
| | | ? isAllEmpty(meta?.rank) || |
| | | (meta?.rank === 0 && name !== "Home" && path !== "/") |
| | | (meta?.rank === 0 && name !== "Welcome" && path !== "/welcome") |
| | | ? true |
| | | : false |
| | | : false; |
| | |
| | | |
| | | /** 处理动态路由(后端返回的路由) */ |
| | | function handleAsyncRoutes(routeList) { |
| | | if (routeList.length === 0) { |
| | | if (routeList?.length === 0) { |
| | | usePermissionStoreHook().handleWholeMenus(routeList); |
| | | } else { |
| | | formatFlatteningRoutes(addAsyncRoutes(routeList)).map( |
| | |
| | | if (!router.hasRoute(v?.name)) router.addRoute(v); |
| | | const flattenRouters: any = router |
| | | .getRoutes() |
| | | .find(n => n.path === "/"); |
| | | .find(n => n.path === "/welcome"); |
| | | // 保持router.options.routes[0].children与path为"/"的children一致,防止数据不一致导致异常 |
| | | flattenRouters.children = router.options.routes[0].children; |
| | | router.addRoute(flattenRouters); |
| | |
| | | } else { |
| | | return new Promise(resolve => { |
| | | getAsyncRoutes().then(({ data }) => { |
| | | handleAsyncRoutes(cloneDeep(data)); |
| | | storageLocal().setItem(key, data); |
| | | // handleAsyncRoutes(cloneDeep(data)); |
| | | // storageLocal().setItem(key, data); |
| | | resolve(router); |
| | | }); |
| | | }); |
| | |
| | | } else { |
| | | return new Promise(resolve => { |
| | | getAsyncRoutes().then(({ data }) => { |
| | | handleAsyncRoutes(cloneDeep(data)); |
| | | // handleAsyncRoutes(cloneDeep(data)); |
| | | resolve(router); |
| | | }); |
| | | }); |
| | |
| | | * @returns 返回处理后的一维路由 |
| | | */ |
| | | function formatFlatteningRoutes(routesList: RouteRecordRaw[]) { |
| | | if (routesList.length === 0) return routesList; |
| | | if (routesList?.length === 0) return routesList; |
| | | let hierarchyList = buildHierarchyTree(routesList); |
| | | for (let i = 0; i < hierarchyList.length; i++) { |
| | | if (hierarchyList[i].children) { |
| | |
| | | * @returns 返回将一维数组重新处理成规定路由的格式 |
| | | */ |
| | | function formatTwoStageRoutes(routesList: RouteRecordRaw[]) { |
| | | if (routesList.length === 0) return routesList; |
| | | if (routesList?.length === 0) return routesList; |
| | | const newRoutesList: RouteRecordRaw[] = []; |
| | | routesList.forEach((v: RouteRecordRaw) => { |
| | | if (v.path === "/") { |
| | | if (v.path === "/welcome") { |
| | | newRoutesList.push({ |
| | | component: v.component, |
| | | name: v.name, |
| | |
| | | usePermissionStoreHook().wholeMenus[0]?.children[0] |
| | | ); |
| | | tag && useMultiTagsStoreHook().handleTags("push", topMenu); |
| | | console.log(topMenu, "topMenu"); |
| | | return topMenu; |
| | | } |
| | | |