MainMenu.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <!--
  2. Menu principal de l'application
  3. Prend en paramètre une liste de ItemMenu et les met en forme
  4. -->
  5. <template>
  6. <v-navigation-drawer
  7. v-model="displayMenu"
  8. :rail="isRail"
  9. :disable-resize-watcher="true"
  10. class="theme-secondary main-menu"
  11. >
  12. <div
  13. v-if="(organizationProfile.isArtistProduct || organizationProfile.isTrialActive) && (accessProfile.isCaMember || accessProfile.isAdmin)"
  14. class="btn_trial"
  15. :class="{['btn_mini'] : isRail}"
  16. @click="trialAction()"
  17. >
  18. <v-icon icon="fa fa-ticket" />
  19. <span v-if="organizationProfile.isTrialActive && !isRail"><strong>J-{{organizationProfile.trialCountDown}}</strong><br/></span>
  20. <span v-if="!isRail">{{btnLabel}}</span>
  21. </div>
  22. <template #prepend>
  23. <slot name="title"></slot>
  24. </template>
  25. <v-list open-strategy="single" active-class="active" class="left-menu">
  26. <!-- TODO: que se passe-t-il si le menu ne comprend qu'un seul MenuItem? -->
  27. <div v-for="(item, i) in items" :key="i">
  28. <!-- Cas 1 : l'item n'a pas d'enfants, c'est un lien (ou le menu est en mode réduit) -->
  29. <v-list-item
  30. v-if="!item.children || isRail"
  31. :title="$t(item.label)"
  32. :prepend-icon="item.icon.name"
  33. :href="!isInternalLink(item) ? item.to : undefined"
  34. :to="isInternalLink(item) ? item.to : undefined"
  35. :target="item.target"
  36. exact
  37. height="48px"
  38. class="menu-item"
  39. />
  40. <!-- Cas 2 : l'item a des enfants, c'est un groupe -->
  41. <v-list-group
  42. v-else
  43. expand-icon="fas fa-angle-down"
  44. collapse-icon="fas fa-angle-up"
  45. >
  46. <template #activator="{ props }">
  47. <v-list-item
  48. v-bind="props"
  49. :prepend-icon="item.icon.name"
  50. :title="$t(item.label)"
  51. class="theme-secondary menu-item"
  52. height="48px"
  53. />
  54. </template>
  55. <v-list-item
  56. v-for="child in item.children"
  57. :key="$t(child.label)"
  58. :title="$t(child.label)"
  59. :prepend-icon="child.icon.name"
  60. :href="!isInternalLink(child) ? child.to : undefined"
  61. :to="isInternalLink(child) ? child.to : undefined"
  62. exact
  63. height="38px"
  64. class="theme-secondary-alt"
  65. />
  66. </v-list-group>
  67. </div>
  68. </v-list>
  69. <template #append>
  70. <slot name="foot"></slot>
  71. </template>
  72. </v-navigation-drawer>
  73. <DialogTrialAllReadyDid
  74. :show="showDialog"
  75. @closeDialog = "showDialog = false"
  76. />
  77. </template>
  78. <script setup lang="ts">
  79. import { useMenu } from '~/composables/layout/useMenu'
  80. import { computed } from '@vue/reactivity'
  81. import { useDisplay } from 'vuetify'
  82. import type { MenuGroup, MenuItem } from '~/types/layout'
  83. import UrlUtils from "~/services/utils/urlUtils";
  84. import {useApiLegacyRequestService} from "~/composables/data/useApiLegacyRequestService";
  85. const runtimeConfig = useRuntimeConfig()
  86. const i18n = useI18n()
  87. const organizationProfile = useOrganizationProfileStore()
  88. const accessProfile = useAccessProfileStore()
  89. const { getMenu, hasMenu, isInternalLink, setMenuState, isMenuOpened } = useMenu()
  90. const { apiRequestService } = useApiLegacyRequestService()
  91. const { mdAndUp, lgAndUp } = useDisplay()
  92. const showDialog: Ref<boolean> = ref(false)
  93. const menu = getMenu('Main')
  94. // En vue lg+, on affiche toujours le menu
  95. const displayMenu = computed(() => {
  96. return menu !== null && hasMenu('Main') && (lgAndUp.value || isOpened.value)
  97. })
  98. const isOpened = computed(() => isMenuOpened('Main'))
  99. const items: Array<MenuGroup | MenuItem> = getItems(menu)
  100. // En vue md+, fermer le menu le passe simplement en mode rail
  101. // Sinon, le fermer le masque complètement
  102. const isRail = computed(() => {
  103. return (
  104. menu !== null &&
  105. mdAndUp.value &&
  106. !isOpened.value &&
  107. !items.some((item) => item.expanded)
  108. )
  109. })
  110. const btnLabel = computed(() => {
  111. if(organizationProfile.isTrialActive){
  112. return i18n.t('trial_started')
  113. }
  114. return organizationProfile.principalType === 'ARTISTIC_PRACTICE_ONLY' ? i18n.t('try_premium') : i18n.t('discover_offer')
  115. })
  116. const unwatch = watch(lgAndUp, (newValue, oldValue) => {
  117. // Par défaut si l'écran est trop petit au chargement de la page, le menu doit rester fermé.
  118. if (process.client && menu !== null) {
  119. setMenuState('Main', lgAndUp.value)
  120. }
  121. })
  122. onUnmounted(() => {
  123. unwatch()
  124. })
  125. /**
  126. * Lorsque l'on appuie sur le bouton pour démarrer l'essai / découvrir les offres
  127. */
  128. const trialAction = async () => {
  129. const v1BaseURL = runtimeConfig.baseUrlAdminLegacy || runtimeConfig.public.baseUrlAdminLegacy
  130. if(organizationProfile.isTrialActive){
  131. await navigateTo(UrlUtils.join(v1BaseURL, '#', 'subscribe'), {
  132. external: true
  133. })
  134. }else if(organizationProfile.principalType === 'ARTISTIC_PRACTICE_ONLY'){
  135. try{
  136. await apiRequestService.get('/trial/is_available')
  137. await navigateTo(UrlUtils.join(v1BaseURL, '#', 'trial'), {
  138. external: true
  139. })
  140. }catch(error){
  141. showDialog.value = true
  142. }
  143. }else{
  144. await navigateTo('/subscription')
  145. }
  146. }
  147. /**
  148. * Récupère les menuItem disponibles
  149. * @param menu
  150. */
  151. function getItems(menu: MenuGroup|MenuItem|null) : Array<MenuGroup | MenuItem>{
  152. let items: Array<MenuGroup | MenuItem>
  153. if (menu === null) {
  154. items = []
  155. } else if (menu.hasOwnProperty('children')) {
  156. items = (menu as MenuGroup).children ?? []
  157. } else {
  158. items = [menu]
  159. }
  160. return items;
  161. }
  162. </script>
  163. <style scoped lang="scss">
  164. .v-list-item {
  165. min-height: 10px !important;
  166. }
  167. :deep(.v-list-item-title),
  168. :deep(.v-icon) {
  169. font-size: 14px;
  170. color: rgb(var(--v-theme-on-secondary));
  171. }
  172. .v-list-item__prepend {
  173. margin: 10px 0;
  174. margin-right: 10px !important;
  175. }
  176. .v-application--is-ltr .v-list-group--no-action > .v-list-group__header {
  177. margin-left: 0;
  178. padding-left: 0;
  179. }
  180. .v-application--is-ltr
  181. .v-list-group--no-action
  182. > .v-list-group__items
  183. > .v-list-item {
  184. padding-left: 30px;
  185. }
  186. .v-list-item__content {
  187. padding: 8px 0;
  188. }
  189. .v-list-group__items .v-list-item {
  190. padding-inline-start: 30px !important;
  191. }
  192. .v-list-group--no-action > .v-list-group__header,
  193. .v-list-item {
  194. border-left: 3px solid rgb(var(--v-theme-secondary));
  195. height: 48px;
  196. }
  197. .v-list-item:hover,
  198. .v-list-item.active,
  199. :deep(.v-list-group__items .v-list-item) {
  200. border-left: 3px solid rgb(var(--v-theme-primary));
  201. background-color: rgb(var(--v-theme-secondary-alt)) !important;
  202. color: rgb(var(--v-theme-on-secondary-alt)) !important;
  203. }
  204. :deep(.v-list-group__items .v-list-item-title) {
  205. color: rgb(var(--v-theme-on-secondary-alt));
  206. }
  207. :deep(.v-list-group__items .v-icon) {
  208. color: rgb(var(--v-theme-on-secondary-alt));
  209. }
  210. :deep(.v-list-item .v-icon) {
  211. margin-right: 10px;
  212. }
  213. :deep(.menu-item .fa) {
  214. text-align: center;
  215. }
  216. .btn_trial{
  217. background-color: rgb(var(--v-theme-x-create-btn));
  218. border-radius: 5px;
  219. border: 1px solid #fff;
  220. margin-left: 15px;
  221. margin-right: 15px;
  222. font-size: 12px;
  223. text-align: center;
  224. color:#000;
  225. margin-top: 5px;
  226. padding: 5px;
  227. padding-left: 10px;
  228. padding-right: 10px;
  229. cursor: pointer;
  230. white-space: pre-line;
  231. .v-icon{
  232. font-size: 15px;
  233. color:#000;
  234. padding-right: 5px;
  235. }
  236. }
  237. .btn_mini{
  238. font-size: 17px;
  239. margin-left: 7px;
  240. margin-right: 7px;
  241. padding: 0px;
  242. .v-icon{
  243. padding-right: 0px;
  244. }
  245. }
  246. </style>