From f336f51887d49bfd52f72f526fdd6b6bfff682e5 Mon Sep 17 00:00:00 2001 From: Dede Fuji Abdul Date: Thu, 19 Oct 2023 12:08:40 +0700 Subject: [PATCH] update --- .gitignore | 2 +- src/utils/route.ts | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/utils/route.ts diff --git a/.gitignore b/.gitignore index f829e12..08910b9 100644 --- a/.gitignore +++ b/.gitignore @@ -27,4 +27,4 @@ coverage *.njsproj *.sln *.sw? -*.ts \ No newline at end of file +data.ts \ No newline at end of file diff --git a/src/utils/route.ts b/src/utils/route.ts new file mode 100644 index 0000000..55a4aa4 --- /dev/null +++ b/src/utils/route.ts @@ -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 + }) +} \ No newline at end of file