Menu.vue 3.4 KB

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