MainMenu.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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, openMenu, isMenuOpened } = useMenu()
  73. const { mdAndUp } = useDisplay()
  74. const menu = buildMenu('Main')
  75. const hasMainMenu = computed(() => hasMenu('Main'))
  76. const isOpened = computed(() => isMenuOpened('Main'))
  77. // En vue md+, on affiche toujours le menu
  78. const isRail = computed(() => mdAndUp.value && !isOpened.value)
  79. const displayMenu = computed(() => hasMainMenu && (mdAndUp.value || isOpened.value))
  80. const unwatch = watch(mdAndUp, (newValue, oldValue) => {
  81. // Par défaut si l'écran est trop petit au chargement de la page, le menu doit rester fermé.
  82. if (process.client && mdAndUp.value) {
  83. openMenu('Main')
  84. }
  85. })
  86. onUnmounted(() => {
  87. unwatch()
  88. })
  89. </script>
  90. <style scoped lang="scss">
  91. .v-list-item {
  92. min-height: 10px !important;
  93. }
  94. :deep(.v-list-item-title),
  95. :deep(.v-icon),
  96. {
  97. font-size: 14px;
  98. color: rgb(var(--v-theme-ot-menu-color));
  99. }
  100. .v-list-item__prepend {
  101. margin: 10px 0;
  102. margin-right: 10px !important;
  103. }
  104. .v-application--is-ltr .v-list-group--no-action > .v-list-group__header {
  105. margin-left: 0;
  106. padding-left: 0;
  107. }
  108. .v-application--is-ltr .v-list-group--no-action > .v-list-group__items > .v-list-item {
  109. padding-left: 30px;
  110. }
  111. .v-list-item__content {
  112. padding: 8px 0;
  113. }
  114. .v-list-group__items .v-list-item {
  115. padding-inline-start: 30px !important;
  116. }
  117. .v-list-group--no-action > .v-list-group__header,
  118. .v-list-item
  119. {
  120. border-left:3px solid rgb(var(--v-theme-ot-dark-grey));
  121. height: 48px;
  122. }
  123. .v-list-item:hover,
  124. .v-list-item.active,
  125. :deep(.v-list-group__items .v-list-item)
  126. {
  127. border-left: 3px solid rgb(var(--v-theme-ot-green));
  128. background: rgb(var(--v-theme-ot-dark-grey-hover));
  129. }
  130. :deep(.v-list-group__items .v-list-item-title) {
  131. color: rgb(var(--v-theme-ot-white));
  132. }
  133. :deep(.v-list-item .v-icon) {
  134. margin-right: 10px;
  135. }
  136. </style>