Breadcrumbs.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <template>
  2. <v-breadcrumbs :items="items" />
  3. </template>
  4. <script setup lang="ts">
  5. import { computed } from 'vue'
  6. import type { ComputedRef } from 'vue'
  7. import { useI18n } from 'vue-i18n'
  8. import type { AnyJson } from '~/types/data'
  9. import UrlUtils from '~/services/utils/urlUtils'
  10. const runtimeConfig = useRuntimeConfig()
  11. const i18n = useI18n()
  12. const router = useRouter()
  13. const items: ComputedRef<Array<AnyJson>> = computed(() => {
  14. const crumbs: Array<AnyJson> = []
  15. const baseUrl =
  16. runtimeConfig.baseUrlAdminLegacy ?? runtimeConfig.public.baseUrlAdminLegacy
  17. crumbs.push({
  18. title: i18n.t('welcome'),
  19. href: UrlUtils.join(baseUrl, '#', 'dashboard'),
  20. })
  21. const pathPart: Array<string> = UrlUtils.split(router.currentRoute.value.path)
  22. let path: string = ''
  23. pathPart.forEach((part) => {
  24. path = UrlUtils.join(path, part)
  25. const match = router.resolve(path)
  26. if (match.name) {
  27. crumbs.push({
  28. title: !parseInt(part, 10)
  29. ? i18n.t(part + '_breadcrumbs')
  30. : i18n.t('item'),
  31. exact: true,
  32. to: path,
  33. })
  34. }
  35. })
  36. return crumbs
  37. })
  38. </script>
  39. <style scoped lang="scss">
  40. :deep(a.v-breadcrumbs-item--disabled) {
  41. color: rgb(var(--v-theme-on-neutral)) !important;
  42. opacity: 1 !important;
  43. }
  44. </style>