diff --git a/src/config/route.js b/src/config/route.js new file mode 100644 index 00000000..fe1eb21a --- /dev/null +++ b/src/config/route.js @@ -0,0 +1,9 @@ +// 静态路由配置 *书写格式与动态路由格式一致,全部经由框架统一转换 +// +// routes 显示在左侧菜单中的路由(显示顺序在动态路由之前) +// otherRoutes 非菜单系的路由(类似登录,注册等脱离菜单系的视图) + +export default { + routes: [], + otherRoutes: [] +} diff --git a/src/layout/components/sideM.vue b/src/layout/components/sideM.vue index 839e1e28..94f58fc8 100644 --- a/src/layout/components/sideM.vue +++ b/src/layout/components/sideM.vue @@ -35,7 +35,7 @@ }, created() { - var menu = this.$TOOL.data.get("MENU"); + var menu = this.$router.sc_getMenu() this.menu = this.filterUrl(menu) }, diff --git a/src/layout/components/tags.vue b/src/layout/components/tags.vue index 03f1064e..d643e763 100644 --- a/src/layout/components/tags.vue +++ b/src/layout/components/tags.vue @@ -67,11 +67,13 @@ } }, created() { - var menu = this.$TOOL.data.get("MENU") + var menu = this.$router.sc_getMenu() var dashboardRoute = this.treeFind(menu, node => node.path==this.$CONFIG.DASHBOARD_URL) - dashboardRoute.fullPath = dashboardRoute.path - this.addViewTags(dashboardRoute) - this.addViewTags(this.$route) + if(dashboardRoute){ + dashboardRoute.fullPath = dashboardRoute.path + this.addViewTags(dashboardRoute) + this.addViewTags(this.$route) + } }, mounted() { this.tagDrop(); diff --git a/src/layout/index.vue b/src/layout/index.vue index c0f2e05f..98b772b8 100644 --- a/src/layout/index.vue +++ b/src/layout/index.vue @@ -218,7 +218,7 @@ created() { this.onLayoutResize(); window.addEventListener('resize', this.onLayoutResize); - var menu = this.$TOOL.data.get("MENU"); + var menu = this.$router.sc_getMenu(); this.menu = this.filterUrl(menu); this.showThis() }, diff --git a/src/router/index.js b/src/router/index.js index 9c7b2ad6..ff0542ba 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -5,11 +5,19 @@ import NProgress from 'nprogress' import 'nprogress/nprogress.css' import tool from '@/utils/tool'; import systemRouter from './systemRouter'; +import userRoutes from '@/config/route'; import {beforeEach, afterEach} from './scrollBehavior'; //系统路由 const routes = systemRouter +//插入转换且扁平化的静态路由 +var u_Routes = filterAsyncRouter(userRoutes.routes) + u_Routes = flatAsyncRoutes(u_Routes) +var otherRoutes = filterAsyncRouter(userRoutes.otherRoutes) +routes[0].children = u_Routes +routes.push(...otherRoutes) + //系统特殊路由 const routes_404 = { path: "/:pathMatch(.*)*", @@ -60,7 +68,7 @@ router.beforeEach(async (to, from, next) => { } //加载API路由 if(!isGetApiRouter){ - let menu = tool.data.get("MENU"); + let menu = tool.data.get("MENU") || []; var apiRouter = filterAsyncRouter(menu); apiRouter = flatAsyncRoutes(apiRouter) apiRouter.forEach(item => { @@ -89,6 +97,13 @@ router.onError((error) => { }); }); +//入侵追加自定义方法、对象 +router.sc_getMenu = () => { + var systemMenu = tool.data.get("MENU") || [] + var menu = [...userRoutes.routes, ...systemMenu]; + return menu +} + //转换 function filterAsyncRouter(routerMap) { const accessedRouters = []