加入静态路由配置

This commit is contained in:
sc 2021-11-10 10:08:35 +08:00
parent 28be6aaa0b
commit 9ef3904c51
5 changed files with 33 additions and 7 deletions

9
src/config/route.js Normal file
View File

@ -0,0 +1,9 @@
// 静态路由配置 *书写格式与动态路由格式一致,全部经由框架统一转换
//
// routes 显示在左侧菜单中的路由(显示顺序在动态路由之前)
// otherRoutes 非菜单系的路由(类似登录,注册等脱离菜单系的视图)
export default {
routes: [],
otherRoutes: []
}

View File

@ -35,7 +35,7 @@
},
created() {
var menu = this.$TOOL.data.get("MENU");
var menu = this.$router.sc_getMenu()
this.menu = this.filterUrl(menu)
},

View File

@ -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();

View File

@ -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()
},

View File

@ -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 = []