salix-front/src/components/LeftMenu.vue

46 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-04-01 10:58:41 +00:00
const moduleRoutes = mainRoute && mainRoute.children || []
2022-04-01 10:58:41 +00:00
const modules = ref([]);
for (const route of moduleRoutes) {
const module = {
path: route.path,
name: route.name.toLowerCase(),
roles: []
};
2022-04-01 10:58:41 +00:00
if (route.meta) {
Object.assign(module, route.meta);
}
2022-04-01 10:58:41 +00:00
modules.value.push(module);
}
</script>
<template>
<q-list padding>
2022-04-01 10:58:41 +00:00
<template v-for="module in modules" :key="module.title">
<q-item
clickable
v-ripple
2022-04-01 10:58:41 +00:00
:to="{ path: module.path }"
v-if="!module.roles.length || hasAny(module.roles)"
active-class="text-orange"
>
2022-04-01 10:58:41 +00:00
<q-item-section avatar :if="module.icon">
<q-icon :name="module.icon" />
</q-item-section>
2022-04-01 10:58:41 +00:00
<q-item-section>{{ t(`${module.name}.pageTitles.${module.title}`) }}</q-item-section>
</q-item>
</template>
</q-list>
</template>