0
0
Fork 0

feat: refs #6900 hide menu item

This commit is contained in:
Jorge Penadés 2024-09-02 13:15:06 +02:00
parent be63c8a7fa
commit f24daa4ebd
5 changed files with 46 additions and 3 deletions

View File

@ -1,6 +1,6 @@
<script setup>
import axios from 'axios';
import { onMounted, ref, reactive } from 'vue';
import { onMounted, watch, ref, reactive } from 'vue';
import { useI18n } from 'vue-i18n';
import { QSeparator, useQuasar } from 'quasar';
import { useRoute } from 'vue-router';
@ -29,6 +29,15 @@ onMounted(async () => {
getRoutes();
});
watch(
() => route.matched,
() => {
items.value = [];
getRoutes();
},
{ deep: true }
);
function findMatches(search, item) {
const matches = [];
function findRoute(search, item) {
@ -52,7 +61,7 @@ function addChildren(module, route, parent) {
const matches = findMatches(mainMenus, route);
for (const child of matches) {
navigation.addMenuItem(module, child, parent);
if (!child.meta.hidden) navigation.addMenuItem(module, child, parent);
}
}
}

View File

@ -72,7 +72,7 @@ if (props.baseUrl) {
<QPage>
<VnSubToolbar />
<div :class="[useCardSize(), $attrs.class]">
<RouterView />
<RouterView :key="$route.path" />
</div>
</QPage>
</QPageContainer>

View File

@ -3,6 +3,8 @@ import VnCard from 'components/common/VnCard.vue';
import InvoiceInDescriptor from './InvoiceInDescriptor.vue';
import InvoiceInFilter from '../InvoiceInFilter.vue';
import InvoiceInSearchbar from '../InvoiceInSearchbar.vue';
import axios from 'axios';
import { onBeforeRouteUpdate } from 'vue-router';
const filter = {
include: [
@ -20,6 +22,20 @@ const filter = {
{ relation: 'currency' },
],
};
onBeforeRouteUpdate(async (to) => {
const card = to.matched.find((route) => route.name === 'InvoiceInCard');
const corrective = card.children.find(
(route) => route.name === 'InvoiceInCorrective'
);
const isRectificative = !!(
await axios.get('InvoiceInCorrections', {
params: { filter: { where: { correctingFk: to.params.id } } },
})
).data.length;
corrective.meta.hidden = !isRectificative;
});
</script>
<template>
<VnCard

View File

@ -1,4 +1,5 @@
import { RouterView } from 'vue-router';
import axios from 'axios';
export default {
path: '/invoice-in',
@ -63,6 +64,22 @@ export default {
path: ':id',
component: () => import('src/pages/InvoiceIn/Card/InvoiceInCard.vue'),
redirect: { name: 'InvoiceInSummary' },
beforeEnter: async (to, from, next) => {
const isRectificative = !!(
await axios.get('InvoiceInCorrections', {
params: { filter: { where: { correctingFk: to.params.id } } },
})
).data.length;
const card = to.matched.find((route) => route.name === 'InvoiceInCard');
const corrective = card.children.find(
(route) => route.name === 'InvoiceInCorrective'
);
corrective.meta.hidden = !isRectificative;
next();
},
children: [
{
name: 'InvoiceInSummary',

View File

@ -56,6 +56,7 @@ export const useNavigationStore = defineStore('navigationStore', () => {
function addMenuItem(module, route, parent) {
const { meta } = route;
let { menuChildren = null } = meta;
if (meta.hidden) return;
if (menuChildren)
menuChildren = menuChildren.map(({ name, title, icon }) => ({
name,