Breadcrumbs.vue 1018 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <template>
  2. <v-breadcrumbs
  3. :items="items"
  4. />
  5. </template>
  6. <script setup lang="ts">
  7. import {useRouter, useRuntimeConfig} from "#app";
  8. import {computed, ComputedRef} from "@vue/reactivity";
  9. import {AnyJson} from "~/types/data";
  10. import {useI18n} from "vue-i18n";
  11. import Url from "~/services/utils/url";
  12. const runtimeConfig = useRuntimeConfig()
  13. const i18n = useI18n()
  14. const router = useRouter()
  15. const items: ComputedRef<Array<AnyJson>> = computed(() => {
  16. const crumbs:Array<AnyJson> = []
  17. crumbs.push({
  18. title: i18n.t('welcome'),
  19. href: runtimeConfig.baseUrlAdminLegacy
  20. })
  21. const pathPart: Array<string> = Url.split(router.currentRoute.value.path)
  22. let path: string = ''
  23. pathPart.forEach((part) => {
  24. path = `${path}/${part}`
  25. const match = router.resolve(path)
  26. if (match.name !== null) {
  27. crumbs.push({
  28. title: !parseInt(part, 10) ? i18n.t(part + '_breadcrumbs') : i18n.t('item'),
  29. exact: true,
  30. to: path
  31. })
  32. }
  33. })
  34. return crumbs
  35. })
  36. </script>