fix Bug or add example

This commit is contained in:
Ah jung
2021-07-16 17:41:11 +08:00
parent a6aa6d4d6d
commit b4857a7559
27 changed files with 780 additions and 304 deletions

View File

@@ -1,8 +1,7 @@
import { adminMenus } from '@/api/system/menu'
import { constantRouterComponents, constantRouterIcon } from './constantRouterComponents'
import router from '@/router/index'
import { constantRouter, asyncRoutes } from '@/router/index'
import { NEmpty } from 'naive-ui'
import { constantRouter } from '@/router/index'
import { RouteRecordRaw } from 'vue-router'
/**
@@ -12,9 +11,9 @@ import { RouteRecordRaw } from 'vue-router'
* @param parent
* @returns {*}
*/
export const routerGenerator = (routerMap, parent) => {
export const routerGenerator = (routerMap, parent?):any[] => {
return routerMap.map(item => {
const currentRouter = {
const currentRouter:any = {
// 路由地址 动态拼接生成如 /dashboard/workplace
path: `${ parent && parent.path || '' }/${ item.path }`,
// 路由名称,建议唯一
@@ -53,12 +52,6 @@ export const generatorDynamicRouter = (): Promise<RouteRecordRaw[]> => {
adminMenus()
.then((result) => {
const routeList = routerGenerator(result)
// 设置模块重定向到菜单
// routeList.forEach((item) => {
// if (item.children?.length > 0 && !item.redirect) {
// item.redirect = { name: item.children[0].name }
// }
// })
const asyncRoutesList = [...constantRouter, ...routeList]
asyncRoutesList.forEach(item => {
router.addRoute(item)