Menu.vue 3.7 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
  19. :defaultImage="menu.icon.avatarByDefault"
  20. :width="30"
  21. />
  22. </v-avatar>
  23. <v-icon v-else :icon="menu.icon.name" class="on-primary" />
  24. </v-btn>
  25. <v-tooltip :activator="btn" :text="$t(menu.label)" location="bottom" />
  26. <v-menu
  27. :activator="btn"
  28. :model-value="isOpened()"
  29. @update:modelValue="onStateUpdated"
  30. >
  31. <v-card>
  32. <v-card-title class="theme-neutral text-body-2 font-weight-bold">
  33. {{ $t(menu.label) }}
  34. </v-card-title>
  35. <v-card-text class="ma-0 pa-0 header-menu">
  36. <v-list density="compact" :subheader="true">
  37. <template v-for="(child, index) in menu.children" :key="index">
  38. <v-list-item
  39. :id="child.label"
  40. :href="!isInternalLink(child) ? child.to : undefined"
  41. :to="isInternalLink(child) ? child.to : undefined"
  42. >
  43. <span v-if="child.icon" class="pr-2 d-flex align-center">
  44. <v-avatar
  45. v-if="menu.icon.avatarId || child.icon.avatarByDefault"
  46. size="30"
  47. >
  48. <UiImage
  49. :imageId="child.icon.avatarId"
  50. :defaultImage="child.icon.avatarByDefault"
  51. :width="30"
  52. />
  53. </v-avatar>
  54. <v-icon v-else class="on-primary" size="small">
  55. {{ child.icon.name }}
  56. </v-icon>
  57. </span>
  58. <span>{{
  59. translateLabel ? $t(child.label) : child.label
  60. }}</span>
  61. </v-list-item>
  62. </template>
  63. </v-list>
  64. </v-card-text>
  65. <v-card-actions
  66. v-if="menu.actions.length > 0"
  67. class="ma-0 pa-0 theme-primary"
  68. >
  69. <template v-for="(action, index) in menu.actions" :key="index">
  70. <v-list-item
  71. :id="action.label"
  72. :href="!isInternalLink(action) ? action.to : undefined"
  73. :to="isInternalLink(action) ? action.to : undefined"
  74. >
  75. <v-list-item-title
  76. class="text-body-2"
  77. v-text="$t(action.label)"
  78. />
  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 { useMenu } from '~/composables/layout/useMenu'
  88. import { computed, ref } from '@vue/reactivity'
  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: any) => {
  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>