salix-front/src/components/LeftMenu.vue

49 lines
1.3 KiB
Vue
Raw Normal View History

2022-03-28 07:06:36 +00:00
<script setup>
import { ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { useRole } from 'src/composables/useRole';
import routes from 'src/router/routes';
const { t } = useI18n();
const { hasAny } = useRole();
const mainRoute = routes.find(route => route.path === '/');
2022-03-28 07:06:36 +00:00
const modules = mainRoute && mainRoute.children || []
2022-03-28 07:06:36 +00:00
const items = ref([]);
for (const module of modules) {
2022-03-28 07:06:36 +00:00
const item = {
path: module.path,
roles: []
};
if (module.meta) {
2022-03-28 07:06:36 +00:00
const meta = module.meta;
item.title = meta.title;
item.icon = meta.icon;
item.roles = meta.roles || [];
}
items.value.push(item);
}
</script>
<template>
<q-list padding>
<template v-for="route in items" :key="route.title">
<q-item
clickable
v-ripple
:to="{ path: route.path }"
v-if="!route.roles.length || hasAny(route.roles)"
active-class="text-orange"
>
<q-item-section avatar :if="route.icon">
<q-icon :name="route.icon" />
</q-item-section>
<q-item-section>{{ t(`pages.${route.title}`) }}</q-item-section>
</q-item>
</template>
</q-list>
</template>