Menu.vue 3.4 KB

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