Menu.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. width="48px"
  11. size="small"
  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="text-ot-white"
  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="ot-header-menu 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. <v-list-item-title>
  52. <span v-if="child.icon">
  53. <v-avatar v-if="menu.icon.avatarId || child.icon.avatarByDefault" size="30">
  54. <UiImage :id="child.icon.avatarId" :defaultImage="child.icon.avatarByDefault" :width="30"></UiImage>
  55. </v-avatar>
  56. <v-icon v-else class="text-ot-white" size="small">
  57. {{ child.icon.name }}
  58. </v-icon>
  59. </span>
  60. <span v-if="translateLabel">{{$t(child.label)}}</span>
  61. <span v-else>{{child.label}}</span>
  62. </v-list-item-title>
  63. </v-list-item>
  64. </template>
  65. </v-list>
  66. </v-card-text>
  67. <v-card-actions v-if="menu.actions.length > 0" class="ma-0 pa-0 actions">
  68. <template v-for="(action, index) in menu.actions" :key="index">
  69. <v-list-item
  70. :id="action.label"
  71. :href="!isInternalLink(action) ? action.to : undefined"
  72. :to="isInternalLink(action) ? action.to : undefined"
  73. >
  74. <v-list-item-title class="text-body-2" v-text="$t(action.label)"/>
  75. </v-list-item>
  76. </template>
  77. </v-card-actions>
  78. </v-card>
  79. </v-menu>
  80. </div>
  81. </template>
  82. <script setup lang="ts">
  83. import {useMenu} from "~/composables/layout/useMenu";
  84. import {computed, ref} from "@vue/reactivity";
  85. const props = defineProps({
  86. name: {
  87. type: String,
  88. required: true
  89. },
  90. translateLabel: {
  91. type: Boolean,
  92. required: false,
  93. default: true
  94. }
  95. })
  96. const { getMenu, isInternalLink, hasMenu, setMenuState, isMenuOpened } = 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. .actions {
  107. background: rgb(var(--v-theme-ot-green));
  108. color: white;
  109. }
  110. </style>