update
This commit is contained in:
parent
4633851c6a
commit
f336f51887
2
.gitignore
vendored
2
.gitignore
vendored
@ -27,4 +27,4 @@ coverage
|
|||||||
*.njsproj
|
*.njsproj
|
||||||
*.sln
|
*.sln
|
||||||
*.sw?
|
*.sw?
|
||||||
*.ts
|
data.ts
|
40
src/utils/route.ts
Normal file
40
src/utils/route.ts
Normal 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
|
||||||
|
})
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user