policeSecurity/superManagement/src/router/staticRouters.ts

71 lines
1.9 KiB
TypeScript
Raw Normal View History

2024-08-29 17:06:00 +08:00
import {RouteRecordRaw} from "vue-router";
2024-08-30 17:03:25 +08:00
import {SYSTEM_MENUS} from "@/config";
import {SystemMenu} from "@/types/config";
const routerClassify: Record<'layout' | 'full', RouteRecordRaw[]> = {
layout: [],
full: []
}
2024-08-30 17:03:25 +08:00
/**
*
*/
const extractMenuToRouter = () => {
2024-08-30 17:03:25 +08:00
const traverse = (data: SystemMenu[]) => {
data.forEach(item => {
if (item.type === 'dir' && item.children && item.children.length > 0) {
traverse(item.children)
} else {
if (!item.isFull) {
routerClassify.layout.push({
path: item.path,
name: item.name,
meta: {
title: item.title
},
component: item.component
} as RouteRecordRaw)
} else {
routerClassify.full.push({
path: item.path,
name: item.name,
meta: {
title: item.title
},
component: item.component
} as RouteRecordRaw)
}
2024-08-30 17:03:25 +08:00
}
})
}
traverse(SYSTEM_MENUS)
}
2024-08-29 17:06:00 +08:00
extractMenuToRouter()
2024-08-29 17:06:00 +08:00
export const staticRouter: RouteRecordRaw[] = [
{
path: '/login',
name: 'login',
meta: {
title: '登录',
},
component: () => import("@/views/login.vue"),
}, {
path: "/",
redirect: '/index',
}, {
path: '/layout',
name: 'layout',
redirect: '/index',
2024-08-30 17:03:25 +08:00
component: () => import("@/components/layout/Layout.vue"),
children: routerClassify.layout
},
...routerClassify.full,
{
2024-08-30 17:03:25 +08:00
path: '/test',
name: 'test',
component: () => import("@/views/test.vue"),
},
2024-08-29 17:06:00 +08:00
]