Card.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <!--
  2. VCard proposant une option dans la boite de dialogue "Assistant de création"
  3. La carte peut prendre en paramètres des options `to` et `href` :
  4. Si `to` est défini et pas `href`, la carte mène simplement à un nouveau menu dans le wizard.
  5. Si `href` est défini, et pas `to`, la carte se comporte comme un lien, et doit rediriger la page vers `href` au clic.
  6. Enfin, si les deux sont définis, l'url est envoyée au composant parent pour être mémorisée, et la carte mène ensuite à
  7. un nouveau menu dans le wizard, qui permettra d'affiner l'url, par exemple en lui ajoutant une query.
  8. -->
  9. <template>
  10. <v-card
  11. class="col-md-6"
  12. color=""
  13. :flat="true"
  14. border="solid 1px"
  15. @click="onClick"
  16. >
  17. <v-row :no-gutters="true" style="height: 100px">
  18. <v-col cols="3" class="flex-grow-0 flex-shrink-0 d-flex justify-center">
  19. <v-icon
  20. :icon="icon"
  21. size="50"
  22. class="ma-2 pa-2 align-self-center text-neutral-strong"
  23. />
  24. </v-col>
  25. <v-col
  26. cols="9"
  27. align-self="center"
  28. class="pl-2 infos-container flex-grow-1 flex-shrink-1"
  29. >
  30. <h4 class="text-primary">{{ $t(title) }}</h4>
  31. <p class="text-neutral-strong">
  32. {{ $t(textContent) }}
  33. </p>
  34. </v-col>
  35. </v-row>
  36. </v-card>
  37. </template>
  38. <script setup lang="ts">
  39. import type {PropType} from "@vue/runtime-core";
  40. import {MENU_LINK_TYPE} from "~/types/enum/layout";
  41. import {useAdminUrl} from "~/composables/utils/useAdminUrl";
  42. import UrlUtils from "~/services/utils/urlUtils";
  43. const props = defineProps({
  44. /**
  45. * Target location in the wizard
  46. */
  47. to: {
  48. type: String,
  49. required: false,
  50. default: null
  51. },
  52. /**
  53. * Target url
  54. */
  55. href: {
  56. type: String,
  57. required: false,
  58. default: null
  59. },
  60. /**
  61. * Target url
  62. */
  63. linkType: {
  64. type: Number as PropType<MENU_LINK_TYPE>,
  65. required: false,
  66. default: MENU_LINK_TYPE.V1
  67. },
  68. /**
  69. * Title displayed on the card
  70. */
  71. title: {
  72. type: String,
  73. required: true
  74. },
  75. /**
  76. * Description displayed on the card
  77. */
  78. textContent: {
  79. type: String,
  80. required: true
  81. },
  82. /**
  83. * Icon displayed on the card
  84. */
  85. icon: {
  86. type: String,
  87. required: true
  88. }
  89. })
  90. const emit = defineEmits(['click'])
  91. const { makeAdminUrl } = useAdminUrl()
  92. let url: string | null = null;
  93. if (props.href !== null) {
  94. switch (props.linkType) {
  95. case MENU_LINK_TYPE.V1:
  96. url = makeAdminUrl(props.href)
  97. break;
  98. case MENU_LINK_TYPE.EXTERNAL:
  99. url = UrlUtils.prependHttps(props.href)
  100. break;
  101. default:
  102. url = props.href
  103. }
  104. }
  105. const onClick = () => {
  106. emit('click', props.to, url)
  107. }
  108. </script>
  109. <style lang="scss" scoped>
  110. h4 {
  111. font-size: 15px;
  112. font-weight: bold;
  113. margin-bottom: 6px;
  114. }
  115. p {
  116. font-size: 13px;
  117. }
  118. .infos-container {
  119. padding: 15px 0;
  120. }
  121. .v-card:hover {
  122. cursor: pointer;
  123. background: rgb(var(--v-theme-primary-alt));
  124. }
  125. </style>