Menu.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 width="48px" size="small">
  8. <v-avatar v-if="menu.icon.avatarId || menu.icon.avatarByDefault" size="30">
  9. <UiImage :id="menu.icon.avatarId" :defaultImage="menu.icon.avatarByDefault" :width="30"></UiImage>
  10. </v-avatar>
  11. <v-icon v-else class="text-ot-white">
  12. {{ menu.icon.name }}
  13. </v-icon>
  14. </v-btn>
  15. <v-tooltip :activator="btn" :text="$t(menu.label)" location="bottom" />
  16. <v-menu
  17. :activator="btn"
  18. :model-value="isOpened()"
  19. location="start"
  20. @update:modelValue="onStateUpdated"
  21. >
  22. <v-card>
  23. <v-card-title class="ot-header-menu text-body-2 font-weight-bold">
  24. {{$t(menu.label)}}
  25. </v-card-title>
  26. <v-card-text class="ma-0 pa-0 header-menu">
  27. <v-list density="compact" :subheader="true">
  28. <template v-for="(child, index) in menu.children" :key="index">
  29. <v-list-item
  30. :id="child.label"
  31. :href="!isInternalLink(child) ? child.to : undefined"
  32. :to="isInternalLink(child) ? child.to : undefined"
  33. >
  34. <v-list-item-title>
  35. <span v-if="child.icon">
  36. <v-avatar v-if="menu.icon.avatarId || child.icon.avatarByDefault" size="30">
  37. <UiImage :id="child.icon.avatarId" :defaultImage="child.icon.avatarByDefault" :width="30"></UiImage>
  38. </v-avatar>
  39. <v-icon v-else class="text-ot-white" size="small">
  40. {{ child.icon.name }}
  41. </v-icon>
  42. </span>
  43. <span>{{$t(child.label)}}</span>
  44. </v-list-item-title>
  45. </v-list-item>
  46. </template>
  47. </v-list>
  48. </v-card-text>
  49. <v-card-actions v-if="menu.actions.length > 0" class="ma-0 pa-0 actions">
  50. <template v-for="(action, index) in menu.actions" :key="index">
  51. <v-list-item
  52. :id="action.label"
  53. :href="!isInternalLink(action) ? action.to : undefined"
  54. :to="isInternalLink(action) ? action.to : undefined"
  55. >
  56. <v-list-item-title class="text-body-2" v-text="$t(action.label)"/>
  57. </v-list-item>
  58. </template>
  59. </v-card-actions>
  60. </v-card>
  61. </v-menu>
  62. </div>
  63. </template>
  64. <script setup lang="ts">
  65. import {useMenu} from "~/composables/layout/useMenu";
  66. import {computed, ref} from "@vue/reactivity";
  67. const props = defineProps({
  68. name: {
  69. type: String,
  70. required: true
  71. }
  72. })
  73. const { buildMenu, isInternalLink, hasMenu, setMenuState, isMenuOpened } = useMenu()
  74. const menu = buildMenu(props.name)
  75. const displayMenu = computed(() => hasMenu(props.name))
  76. const isOpened = () => isMenuOpened(props.name)
  77. const onStateUpdated = (e: any) => {
  78. setMenuState(props.name, e)
  79. }
  80. const btn = ref(null)
  81. </script>
  82. <style scoped lang="scss">
  83. .actions {
  84. background: rgb(var(--v-theme-ot-green));
  85. color: white;
  86. }
  87. </style>