2022-03-28 07:06:36 +00:00
|
|
|
<script setup>
|
|
|
|
import { ref } from 'vue';
|
2022-03-15 09:33:28 +00:00
|
|
|
import { useI18n } from 'vue-i18n';
|
|
|
|
import { useRole } from 'src/composables/useRole';
|
|
|
|
import routes from 'src/router/routes';
|
|
|
|
|
|
|
|
const { t } = useI18n();
|
|
|
|
const { hasAny } = useRole();
|
|
|
|
|
2022-05-17 12:58:01 +00:00
|
|
|
const mainRoute = routes.find((route) => route.path === '/');
|
|
|
|
const moduleRoutes = (mainRoute && mainRoute.children) || [];
|
2022-03-15 09:33:28 +00:00
|
|
|
|
2022-04-01 10:58:41 +00:00
|
|
|
const modules = ref([]);
|
|
|
|
for (const route of moduleRoutes) {
|
|
|
|
const module = {
|
2022-05-17 12:58:01 +00:00
|
|
|
stateName: route.name,
|
2022-04-01 10:58:41 +00:00
|
|
|
name: route.name.toLowerCase(),
|
2022-05-17 12:58:01 +00:00
|
|
|
roles: [],
|
2022-03-15 09:33:28 +00:00
|
|
|
};
|
|
|
|
|
2022-04-01 10:58:41 +00:00
|
|
|
if (route.meta) {
|
|
|
|
Object.assign(module, route.meta);
|
2022-03-15 09:33:28 +00:00
|
|
|
}
|
|
|
|
|
2022-05-17 12:58:01 +00:00
|
|
|
if (route.children && route.children.length) {
|
|
|
|
const [moduleMain] = route.children;
|
|
|
|
const routes = moduleMain.children;
|
|
|
|
|
|
|
|
module.children = routes.map((route) => {
|
|
|
|
const submodule = {
|
|
|
|
stateName: route.name,
|
|
|
|
name: route.name,
|
|
|
|
};
|
|
|
|
|
|
|
|
Object.assign(submodule, route.meta);
|
|
|
|
|
|
|
|
return submodule;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-01 10:58:41 +00:00
|
|
|
modules.value.push(module);
|
2022-03-15 09:33:28 +00:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<q-list padding>
|
2022-04-01 10:58:41 +00:00
|
|
|
<template v-for="module in modules" :key="module.title">
|
2022-05-17 12:58:01 +00:00
|
|
|
<template v-if="!module.children">
|
|
|
|
<q-item
|
|
|
|
clickable
|
|
|
|
v-ripple
|
|
|
|
active-class="text-orange"
|
|
|
|
:key="module.title"
|
|
|
|
:to="{ name: module.stateName }"
|
|
|
|
v-if="!module.roles || !module.roles.length || hasAny(module.roles)"
|
|
|
|
>
|
|
|
|
<q-item-section avatar :if="module.icon">
|
|
|
|
<q-icon :name="module.icon" />
|
|
|
|
</q-item-section>
|
|
|
|
<q-item-section>{{ t(`${module.name}.pageTitles.${module.title}`) }}</q-item-section>
|
|
|
|
</q-item>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<template v-if="module.children">
|
|
|
|
<q-expansion-item
|
|
|
|
expand-separator
|
|
|
|
active-class="text-orange"
|
|
|
|
:icon="module.icon"
|
|
|
|
:label="t(`${module.name}.pageTitles.${module.title}`)"
|
|
|
|
v-if="!module.roles || !module.roles.length || hasAny(module.roles)"
|
|
|
|
:to="{ name: module.stateName }"
|
|
|
|
>
|
|
|
|
<template v-for="section in module.children" :key="section.title">
|
|
|
|
<q-item
|
|
|
|
clickable
|
|
|
|
v-ripple
|
|
|
|
active-class="text-orange"
|
|
|
|
:to="{ name: section.stateName }"
|
|
|
|
v-if="!section.roles || !section.roles.length || hasAny(section.roles)"
|
|
|
|
>
|
|
|
|
<q-item-section avatar :if="section.icon">
|
|
|
|
<q-icon :name="section.icon" />
|
|
|
|
</q-item-section>
|
|
|
|
<q-item-section>{{ t(`${module.name}.pageTitles.${section.title}`) }}</q-item-section>
|
|
|
|
</q-item>
|
|
|
|
</template>
|
|
|
|
</q-expansion-item>
|
|
|
|
</template>
|
2022-03-15 09:33:28 +00:00
|
|
|
</template>
|
|
|
|
</q-list>
|
2022-05-17 12:58:01 +00:00
|
|
|
</template>
|