Menu.vue 3.7 KB

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