2018-12-06 18:45:40 +00:00
|
|
|
<template>
|
2018-12-26 09:39:12 +00:00
|
|
|
<div :class="['layout-sidebar', {'active': active}]">
|
2021-02-18 08:26:44 +00:00
|
|
|
<div class="layout-sidebar-filter p-fluid p-input-filled">
|
2021-02-18 08:48:37 +00:00
|
|
|
<AutoComplete v-model="selectedRoute" :suggestions="filteredRoutes" @complete="searchRoute($event)" @item-select="onItemSelect($event)" scrollHeight="300px" placeholder="Search"
|
2021-02-18 08:26:44 +00:00
|
|
|
field="name" optionGroupLabel="name" optionGroupChildren="children">
|
|
|
|
</AutoComplete>
|
|
|
|
</div>
|
2018-12-06 19:23:02 +00:00
|
|
|
<div class="layout-menu">
|
2021-01-04 06:58:56 +00:00
|
|
|
<template v-for="item of menu" :key="item.name">
|
|
|
|
<div class="menu-category">{{item.name}}</div>
|
|
|
|
<div class="menu-items">
|
|
|
|
<template v-for="child of item.children" :key="child.name">
|
|
|
|
<a v-if="child.href" :href="child.href" target="_blank">{{child.name}}</a>
|
|
|
|
<router-link v-if="child.to" :to="child.to">
|
|
|
|
{{child.name}}
|
|
|
|
<Tag v-if="child.badge" :value="child.badge"></Tag>
|
|
|
|
</router-link>
|
|
|
|
<template v-if="child.children">
|
2021-01-15 10:32:37 +00:00
|
|
|
<router-link :to="child.children[0].to" v-slot="{isActive}" custom>
|
2021-01-04 06:58:56 +00:00
|
|
|
<div>
|
2021-02-10 10:49:36 +00:00
|
|
|
<a tabindex="0" @click="toggleSubmenu($event, child.meta[0])">
|
|
|
|
{{child.name}}
|
|
|
|
<Tag v-if="child.badge" :value="child.badge"></Tag>
|
|
|
|
</a>
|
2021-01-04 06:58:56 +00:00
|
|
|
<transition name="p-toggleable-content">
|
|
|
|
<div class="p-toggleable-content" v-show="isSubmenuActive(child.meta[0], isActive)">
|
|
|
|
<ul>
|
|
|
|
<li v-for="(submenuitem, i) of child.children" :key="i">
|
2021-02-10 10:49:36 +00:00
|
|
|
<router-link :to="submenuitem.to">
|
|
|
|
{{submenuitem.name}}
|
|
|
|
<Tag v-if="submenuitem.badge" :value="submenuitem.badge"></Tag>
|
|
|
|
</router-link>
|
2021-01-04 06:58:56 +00:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</transition>
|
|
|
|
</div>
|
|
|
|
</router-link>
|
|
|
|
</template>
|
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
</template>
|
2018-12-06 19:23:02 +00:00
|
|
|
</div>
|
2018-12-06 18:45:40 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-01-04 06:58:56 +00:00
|
|
|
import MenuService from './service/MenuService';
|
2021-02-18 08:26:44 +00:00
|
|
|
import {FilterService,FilterMatchMode} from 'primevue/api';
|
2021-01-04 06:58:56 +00:00
|
|
|
|
2018-12-06 18:45:40 +00:00
|
|
|
export default {
|
2018-12-26 09:36:00 +00:00
|
|
|
props: {
|
2018-12-26 12:24:18 +00:00
|
|
|
active: Boolean
|
2018-12-26 09:36:00 +00:00
|
|
|
},
|
2018-12-06 19:23:02 +00:00
|
|
|
data() {
|
|
|
|
return {
|
2021-01-04 06:58:56 +00:00
|
|
|
activeSubmenus: {},
|
2021-02-18 08:26:44 +00:00
|
|
|
menu: null,
|
|
|
|
filteredRoutes: null,
|
|
|
|
selectedRoute: null,
|
|
|
|
routes: []
|
2018-12-06 19:23:02 +00:00
|
|
|
}
|
|
|
|
},
|
2021-01-04 06:58:56 +00:00
|
|
|
menuService: null,
|
|
|
|
created() {
|
|
|
|
this.menuService = new MenuService();
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.menuService.getMenu().then(data => {
|
|
|
|
this.menu = data;
|
2021-02-18 08:26:44 +00:00
|
|
|
|
2021-02-18 09:08:30 +00:00
|
|
|
data.forEach((route) => {
|
|
|
|
let childRoute = route;
|
|
|
|
childRoute = childRoute.children.filter((childRoute) => {
|
2021-02-18 08:26:44 +00:00
|
|
|
if (childRoute.meta) {
|
2021-02-18 09:08:30 +00:00
|
|
|
this.routes.push(childRoute);
|
2021-02-18 08:26:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return !childRoute.meta;
|
|
|
|
})
|
|
|
|
|
2021-02-18 09:08:30 +00:00
|
|
|
this.routes.push(route);
|
|
|
|
});
|
2021-01-04 06:58:56 +00:00
|
|
|
})
|
|
|
|
},
|
2018-12-06 19:23:02 +00:00
|
|
|
methods: {
|
2020-05-14 07:27:08 +00:00
|
|
|
toggleSubmenu(event, name) {
|
|
|
|
this.activeSubmenus[name] = this.activeSubmenus[name] ? false: true;
|
|
|
|
this.activeSubmenus = {...this.activeSubmenus};
|
|
|
|
event.preventDefault();
|
2020-05-15 15:43:15 +00:00
|
|
|
},
|
|
|
|
isSubmenuActive(name, routerIsActive) {
|
2020-09-17 11:58:41 +00:00
|
|
|
if (this.activeSubmenus[name]) {
|
|
|
|
return true;
|
2020-05-27 06:55:53 +00:00
|
|
|
}
|
|
|
|
else if (routerIsActive) {
|
|
|
|
this.activeSubmenus[name] = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2021-02-18 08:26:44 +00:00
|
|
|
},
|
|
|
|
searchRoute(event) {
|
|
|
|
let query = event.query;
|
|
|
|
let filteredRoutes = [];
|
|
|
|
|
|
|
|
for (let route of this.routes) {
|
|
|
|
let filteredItems = FilterService.filter(route.children, ['to', 'href'], query, FilterMatchMode.CONTAINS);
|
|
|
|
if (filteredItems && filteredItems.length) {
|
2021-02-18 09:08:30 +00:00
|
|
|
filteredRoutes.push({name: route.name, children: filteredItems});
|
2021-02-18 08:26:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.filteredRoutes = filteredRoutes;
|
|
|
|
},
|
|
|
|
onItemSelect(event) {
|
|
|
|
this.selectedRoute = null;
|
|
|
|
|
|
|
|
if (event.value.to)
|
|
|
|
this.$router.push(event.value.to)
|
|
|
|
else if (event.value.href)
|
|
|
|
window.location.href = event.value.href;
|
2018-12-06 19:23:02 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-06 18:45:40 +00:00
|
|
|
}
|
2020-03-31 13:27:54 +00:00
|
|
|
</script>
|