Menu.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <!--
  2. Menu déroulant générique pour l'affichage des menus du
  3. header principal (configuration, paramètres du compte...)
  4. -->
  5. <template>
  6. <div v-if="displayMenu">
  7. <v-btn ref="btn" icon size="small" class="ml-2">
  8. <v-avatar
  9. v-if="menu.icon.avatarId || menu.icon.avatarByDefault"
  10. size="30"
  11. >
  12. <!-- remplacera l'UiImage en dessous lorsque la gestion des images avec liip sera OK
  13. <UiImage
  14. :imageId="menu.icon.avatarId"
  15. :defaultImage="menu.icon.avatarByDefault"
  16. :width="30"
  17. /> -->
  18. <UiImage :default-image="menu.icon.avatarByDefault" :width="30" />
  19. </v-avatar>
  20. <v-icon v-else :icon="menu.icon.name" class="on-primary" />
  21. </v-btn>
  22. <v-tooltip :activator="btn" :text="$t(menu.label)" location="bottom" />
  23. <v-menu
  24. :activator="btn"
  25. :model-value="isOpened()"
  26. @update:model-value="onStateUpdated"
  27. >
  28. <v-card>
  29. <v-card-title class="theme-neutral text-body-2 font-weight-bold">
  30. {{ $t(menu.label) }}
  31. </v-card-title>
  32. <v-card-text class="ma-0 pa-0 header-menu">
  33. <v-list density="compact" :subheader="true">
  34. <template v-for="(child, index) in menu.children" :key="index">
  35. <v-list-item
  36. :id="child.label"
  37. :href="!isInternalLink(child) ? child.to : undefined"
  38. :to="isInternalLink(child) ? child.to : undefined"
  39. :class="{
  40. 'end-of-section':
  41. 'endOfSubsection' in child && child.endOfSubsection,
  42. }"
  43. >
  44. <span v-if="child.icon" class="pr-2 d-flex align-center">
  45. <v-avatar
  46. v-if="menu.icon.avatarId || child.icon.avatarByDefault"
  47. size="30"
  48. >
  49. <UiImage
  50. :image-id="child.icon.avatarId"
  51. :default-image="child.icon.avatarByDefault"
  52. :width="30"
  53. />
  54. </v-avatar>
  55. <v-icon v-else class="on-primary" size="small">
  56. {{ child.icon.name }}
  57. </v-icon>
  58. </span>
  59. <span>{{
  60. translateLabel ? $t(child.label) : child.label
  61. }}</span>
  62. </v-list-item>
  63. </template>
  64. </v-list>
  65. </v-card-text>
  66. <v-card-actions
  67. v-if="menu.actions.length > 0"
  68. class="ma-0 pa-0 theme-primary"
  69. >
  70. <template v-for="(action, index) in menu.actions" :key="index">
  71. <v-list-item
  72. :id="action.label"
  73. :href="!isInternalLink(action) ? action.to : undefined"
  74. :to="isInternalLink(action) ? action.to : undefined"
  75. >
  76. <v-list-item-title class="text-body-2">
  77. {{ $t(action.label) }}
  78. </v-list-item-title>
  79. </v-list-item>
  80. </template>
  81. </v-card-actions>
  82. </v-card>
  83. </v-menu>
  84. </div>
  85. </template>
  86. <script setup lang="ts">
  87. import { computed, ref } from 'vue'
  88. import { useMenu } from '~/composables/layout/useMenu'
  89. const props = defineProps({
  90. name: {
  91. type: String,
  92. required: true,
  93. },
  94. translateLabel: {
  95. type: Boolean,
  96. required: false,
  97. default: true,
  98. },
  99. })
  100. const { getMenu, isInternalLink, hasMenu, setMenuState, isMenuOpened } =
  101. useMenu()
  102. const menu = getMenu(props.name)
  103. const displayMenu = computed(() => hasMenu(props.name))
  104. const isOpened = () => isMenuOpened(props.name)
  105. const onStateUpdated = (e: boolean) => {
  106. setMenuState(props.name, e)
  107. }
  108. const btn = ref(null)
  109. </script>
  110. <style scoped lang="scss">
  111. :deep(.v-btn .v-icon) {
  112. font-size: 1rem !important;
  113. }
  114. .v-list {
  115. padding: 0;
  116. }
  117. .v-list-item {
  118. width: 100%;
  119. }
  120. .header-menu .v-list .v-list-item:last-child {
  121. border-bottom: none;
  122. }
  123. </style>