Menu.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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="{ 'end-of-section': 'endOfSubsection' in child && child.endOfSubsection }"
  40. >
  41. <span v-if="child.icon" class="pr-2 d-flex align-center">
  42. <v-avatar
  43. v-if="menu.icon.avatarId || child.icon.avatarByDefault"
  44. size="30"
  45. >
  46. <UiImage
  47. :image-id="child.icon.avatarId"
  48. :default-image="child.icon.avatarByDefault"
  49. :width="30"
  50. />
  51. </v-avatar>
  52. <v-icon v-else class="on-primary" size="small">
  53. {{ child.icon.name }}
  54. </v-icon>
  55. </span>
  56. <span>{{
  57. translateLabel ? $t(child.label) : child.label
  58. }}</span>
  59. </v-list-item>
  60. </template>
  61. </v-list>
  62. </v-card-text>
  63. <v-card-actions
  64. v-if="menu.actions.length > 0"
  65. class="ma-0 pa-0 theme-primary"
  66. >
  67. <template v-for="(action, index) in menu.actions" :key="index">
  68. <v-list-item
  69. :id="action.label"
  70. :href="!isInternalLink(action) ? action.to : undefined"
  71. :to="isInternalLink(action) ? action.to : undefined"
  72. >
  73. <v-list-item-title class="text-body-2">
  74. {{ $t(action.label) }}
  75. </v-list-item-title>
  76. </v-list-item>
  77. </template>
  78. </v-card-actions>
  79. </v-card>
  80. </v-menu>
  81. </div>
  82. </template>
  83. <script setup lang="ts">
  84. import { computed, ref } from 'vue'
  85. import { useMenu } from '~/composables/layout/useMenu'
  86. const props = defineProps({
  87. name: {
  88. type: String,
  89. required: true,
  90. },
  91. translateLabel: {
  92. type: Boolean,
  93. required: false,
  94. default: true,
  95. },
  96. })
  97. const { getMenu, isInternalLink, hasMenu, setMenuState, isMenuOpened } =
  98. useMenu()
  99. const menu = getMenu(props.name)
  100. const displayMenu = computed(() => hasMenu(props.name))
  101. const isOpened = () => isMenuOpened(props.name)
  102. const onStateUpdated = (e: boolean) => {
  103. setMenuState(props.name, e)
  104. }
  105. const btn = ref(null)
  106. </script>
  107. <style scoped lang="scss">
  108. :deep(.v-btn .v-icon) {
  109. font-size: 1rem !important;
  110. }
  111. .v-list {
  112. padding: 0;
  113. }
  114. .v-list-item {
  115. width: 100%;
  116. }
  117. .header-menu .v-list .v-list-item:last-child {
  118. border-bottom: none;
  119. }
  120. </style>