✨ 加入静态路由配置
This commit is contained in:
parent
28be6aaa0b
commit
9ef3904c51
|
|
@ -0,0 +1,9 @@
|
||||||
|
// 静态路由配置 *书写格式与动态路由格式一致,全部经由框架统一转换
|
||||||
|
//
|
||||||
|
// routes 显示在左侧菜单中的路由(显示顺序在动态路由之前)
|
||||||
|
// otherRoutes 非菜单系的路由(类似登录,注册等脱离菜单系的视图)
|
||||||
|
|
||||||
|
export default {
|
||||||
|
routes: [],
|
||||||
|
otherRoutes: []
|
||||||
|
}
|
||||||
|
|
@ -35,7 +35,7 @@
|
||||||
|
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
var menu = this.$TOOL.data.get("MENU");
|
var menu = this.$router.sc_getMenu()
|
||||||
this.menu = this.filterUrl(menu)
|
this.menu = this.filterUrl(menu)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,11 +67,13 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
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)
|
var dashboardRoute = this.treeFind(menu, node => node.path==this.$CONFIG.DASHBOARD_URL)
|
||||||
dashboardRoute.fullPath = dashboardRoute.path
|
if(dashboardRoute){
|
||||||
this.addViewTags(dashboardRoute)
|
dashboardRoute.fullPath = dashboardRoute.path
|
||||||
this.addViewTags(this.$route)
|
this.addViewTags(dashboardRoute)
|
||||||
|
this.addViewTags(this.$route)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.tagDrop();
|
this.tagDrop();
|
||||||
|
|
|
||||||
|
|
@ -218,7 +218,7 @@
|
||||||
created() {
|
created() {
|
||||||
this.onLayoutResize();
|
this.onLayoutResize();
|
||||||
window.addEventListener('resize', 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.menu = this.filterUrl(menu);
|
||||||
this.showThis()
|
this.showThis()
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,19 @@ import NProgress from 'nprogress'
|
||||||
import 'nprogress/nprogress.css'
|
import 'nprogress/nprogress.css'
|
||||||
import tool from '@/utils/tool';
|
import tool from '@/utils/tool';
|
||||||
import systemRouter from './systemRouter';
|
import systemRouter from './systemRouter';
|
||||||
|
import userRoutes from '@/config/route';
|
||||||
import {beforeEach, afterEach} from './scrollBehavior';
|
import {beforeEach, afterEach} from './scrollBehavior';
|
||||||
|
|
||||||
//系统路由
|
//系统路由
|
||||||
const routes = systemRouter
|
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 = {
|
const routes_404 = {
|
||||||
path: "/:pathMatch(.*)*",
|
path: "/:pathMatch(.*)*",
|
||||||
|
|
@ -60,7 +68,7 @@ router.beforeEach(async (to, from, next) => {
|
||||||
}
|
}
|
||||||
//加载API路由
|
//加载API路由
|
||||||
if(!isGetApiRouter){
|
if(!isGetApiRouter){
|
||||||
let menu = tool.data.get("MENU");
|
let menu = tool.data.get("MENU") || [];
|
||||||
var apiRouter = filterAsyncRouter(menu);
|
var apiRouter = filterAsyncRouter(menu);
|
||||||
apiRouter = flatAsyncRoutes(apiRouter)
|
apiRouter = flatAsyncRoutes(apiRouter)
|
||||||
apiRouter.forEach(item => {
|
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) {
|
function filterAsyncRouter(routerMap) {
|
||||||
const accessedRouters = []
|
const accessedRouters = []
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue