MainMenu.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <!--
  2. Menu principal de l'application
  3. Prend en paramètre une liste de ItemMenu et les met en forme
  4. -->
  5. <template>
  6. <v-navigation-drawer
  7. v-model="displayMenu"
  8. :rail="isRail"
  9. :disable-resize-watcher="true"
  10. class="bg-ot-dark-grey text-ot-menu-color main-menu"
  11. >
  12. <template #prepend>
  13. <slot name="title"></slot>
  14. </template>
  15. <v-list
  16. open-strategy="single"
  17. active-class="active"
  18. class="left-menu"
  19. >
  20. <div v-for="(item, i) in menu.children" :key="i">
  21. <!-- Cas 1 : l'item n'a pas d'enfants, c'est un lien -->
  22. <v-list-item
  23. v-if="!item.children"
  24. :title="$t(item.label)"
  25. :prepend-icon="item.icon.name"
  26. :href="!isInternalLink(item) ? item.to : undefined"
  27. :to="isInternalLink(item) ? item.to : undefined"
  28. exact
  29. class="text-ot-menu-color"
  30. height="48px"
  31. ></v-list-item>
  32. <!-- Cas 2 : l'item a des enfants, c'est un groupe -->
  33. <v-list-group
  34. v-else
  35. expand-icon="fas fa-angle-right"
  36. collapse-icon="fas fa-angle-down"
  37. class="text-ot-menu-color"
  38. v-model="item.expanded"
  39. >
  40. <template #activator="{ props }">
  41. <v-list-item
  42. v-bind="props"
  43. :prepend-icon="item.icon.name"
  44. :title="$t(item.label)"
  45. class="text-ot-menu-color"
  46. height="48px"
  47. ></v-list-item>
  48. </template>
  49. <v-list-item
  50. v-for="child in item.children"
  51. :key="$t(child.label)"
  52. :title="$t(child.label)"
  53. :prepend-icon="child.icon.name"
  54. :href="!isInternalLink(child) ? child.to : undefined"
  55. :to="isInternalLink(child) ? child.to : undefined"
  56. exact
  57. height="48px"
  58. class="text-ot-white"
  59. ></v-list-item>
  60. </v-list-group>
  61. </div>
  62. </v-list>
  63. <template #append>
  64. <slot name="foot"></slot>
  65. </template>
  66. </v-navigation-drawer>
  67. </template>
  68. <script setup lang="ts">
  69. import {useMenu} from "~/composables/layout/useMenu";
  70. import {computed} from "@vue/reactivity";
  71. import { useDisplay } from 'vuetify'
  72. const { buildMenu, hasMenu, isInternalLink, setMenuState, isMenuOpened } = useMenu()
  73. const { mdAndUp, lgAndUp } = useDisplay()
  74. const menu = buildMenu('Main')
  75. if (menu.value === null) {
  76. throw new Error('No main menu to display')
  77. }
  78. const isOpened = computed(() => isMenuOpened('Main'))
  79. // En vue lg+, on affiche toujours le menu
  80. const displayMenu = computed(() => {
  81. return menu.value !== null && hasMenu('Main') && (lgAndUp.value || isOpened.value)
  82. })
  83. // En vue md+, fermer le menu le passe simplement en mode rail
  84. // Sinon, le fermer le masque complètement
  85. const isRail = computed(() => {
  86. return menu.value !== null && mdAndUp.value && !isOpened.value
  87. })
  88. const unwatch = watch(lgAndUp, (newValue, oldValue) => {
  89. // Par défaut si l'écran est trop petit au chargement de la page, le menu doit rester fermé.
  90. if (process.client && menu.value !== null) {
  91. setMenuState('Main', lgAndUp.value)
  92. }
  93. })
  94. onUnmounted(() => {
  95. unwatch()
  96. })
  97. </script>
  98. <style scoped lang="scss">
  99. .v-list-item {
  100. min-height: 10px !important;
  101. }
  102. :deep(.v-list-item-title),
  103. :deep(.v-icon),
  104. {
  105. font-size: 14px;
  106. color: rgb(var(--v-theme-ot-menu-color));
  107. }
  108. .v-list-item__prepend {
  109. margin: 10px 0;
  110. margin-right: 10px !important;
  111. }
  112. .v-application--is-ltr .v-list-group--no-action > .v-list-group__header {
  113. margin-left: 0;
  114. padding-left: 0;
  115. }
  116. .v-application--is-ltr .v-list-group--no-action > .v-list-group__items > .v-list-item {
  117. padding-left: 30px;
  118. }
  119. .v-list-item__content {
  120. padding: 8px 0;
  121. }
  122. .v-list-group__items .v-list-item {
  123. padding-inline-start: 30px !important;
  124. }
  125. .v-list-group--no-action > .v-list-group__header,
  126. .v-list-item
  127. {
  128. border-left:3px solid rgb(var(--v-theme-ot-dark-grey));
  129. height: 48px;
  130. }
  131. .v-list-item:hover,
  132. .v-list-item.active,
  133. :deep(.v-list-group__items .v-list-item)
  134. {
  135. border-left: 3px solid rgb(var(--v-theme-ot-green));
  136. background: rgb(var(--v-theme-ot-dark-grey-hover));
  137. }
  138. :deep(.v-list-group__items .v-list-item-title) {
  139. color: rgb(var(--v-theme-ot-white));
  140. }
  141. :deep(.v-list-item .v-icon) {
  142. margin-right: 10px;
  143. }
  144. </style>