|
|
@@ -16,6 +16,7 @@ import {createVNode, defineComponent, h, Ref} from "vue";
|
|
|
import {stringNotBlank} from "@/utils/blank-utils";
|
|
|
import {useUserStore} from "@/pinia/user-store";
|
|
|
import XEUtils from "xe-utils";
|
|
|
+import {eachAndReturnList} from "@/utils/cyRefList";
|
|
|
|
|
|
const router = createRouter({
|
|
|
history: createWebHistory(),
|
|
|
@@ -30,11 +31,12 @@ export const routerMenus: Ref<IntergrationMenu[]> = ref([])
|
|
|
|
|
|
const firstLevelRouter = []
|
|
|
const secondLevelRouter = []
|
|
|
+export const secondLevelRouterKey = new Map<string, string[]>()
|
|
|
|
|
|
function emptyRouter(routers: IntergrationMenu[]) {
|
|
|
routers.forEach((item) => {
|
|
|
const hasChildren = item.children !== null && item.children.length > 0
|
|
|
- if (['EmptyRouter', 'Layout'].includes(item.component) && hasChildren) {
|
|
|
+ if (item.component === 'Layout' && hasChildren) {
|
|
|
item.children?.forEach(child => {
|
|
|
child.path = item.path + '/' + child.path
|
|
|
firstLevelRouter.push(child)
|
|
|
@@ -89,25 +91,23 @@ async function beforeAddRoutes() {
|
|
|
await useUserStore().getUserInfo
|
|
|
routerMenus.value = await getUserMenu()
|
|
|
emptyRouter(XEUtils.clone(routerMenus.value, true))
|
|
|
- const data = convertToRouter([{
|
|
|
- completePath: "/",
|
|
|
- pathParams: '',
|
|
|
- redirect: 'dashboard',
|
|
|
- component: 'Layout',
|
|
|
- icon: "",
|
|
|
- id: 0,
|
|
|
- metaLink: false,
|
|
|
- metaTitle: "",
|
|
|
- name: "",
|
|
|
- path: "/",
|
|
|
- sort: 0,
|
|
|
- type: 0,
|
|
|
+
|
|
|
+ secondLevelRouter.forEach((item) => {
|
|
|
+ const tmp = eachAndReturnList(item.children, (i) => {
|
|
|
+ return i.name
|
|
|
+ })
|
|
|
+ secondLevelRouterKey.set(item.name, tmp)
|
|
|
+ })
|
|
|
+
|
|
|
+ router.addRoute({
|
|
|
+ name: 'Home',
|
|
|
+ path: '/',
|
|
|
+ redirect: '/dashboard',
|
|
|
+ component: () => import('@/layout/index.vue'),
|
|
|
children: [
|
|
|
- ...firstLevelRouter, ...secondLevelRouter
|
|
|
- ],
|
|
|
- }])
|
|
|
- data.forEach(item => {
|
|
|
- router.addRoute(item)
|
|
|
+ ...convertToRouter(firstLevelRouter),
|
|
|
+ ...convertToRouter(secondLevelRouter),
|
|
|
+ ]
|
|
|
})
|
|
|
}
|
|
|
|