This commit is contained in:
Dede Fuji Abdul 2023-10-19 12:08:40 +07:00
parent 4633851c6a
commit f336f51887
2 changed files with 41 additions and 1 deletions

2
.gitignore vendored
View File

@ -27,4 +27,4 @@ coverage
*.njsproj
*.sln
*.sw?
*.ts
data.ts

40
src/utils/route.ts Normal file
View File

@ -0,0 +1,40 @@
import type { MenuItemModel } from './interfaces'
import type { RouteRecordRaw } from 'vue-router'
import {
Gauge,
LightningSlash,
Monitor,
Plugs,
SmileySad,
Swap
} from '@/utils/icons'
const navigationIcon = [
LightningSlash,
SmileySad,
Monitor,
Swap,
Plugs,
Gauge
]
export const convertRouteToMenu = (data: RouteRecordRaw[], basePath: string = '/home', iconIndex: number = 0): MenuItemModel[] => {
return data.filter((i) => i.path !== '').map((item) => {
const convertedItem: MenuItemModel = {
name: item.name?.toString() || '',
path: `${basePath}/${item.path}`,
expanded: false,
icon: undefined,
children: [],
};
if (item.children) {
convertedItem.icon = navigationIcon[iconIndex];
iconIndex = (iconIndex + 1) % navigationIcon.length;
convertedItem.children = convertRouteToMenu(item.children, `${basePath}/${item.path}`, iconIndex);
}
return convertedItem
})
}