Menu.vue 3.6 KB

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