Some checks failed
CI / Test (ubuntu-latest) (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / Lint (ubuntu-latest) (push) Has been cancelled
CI / Lint (windows-latest) (push) Has been cancelled
CI / Check (ubuntu-latest) (push) Has been cancelled
CI / Check (windows-latest) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
Deploy Website on push / Deploy Push Playground Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Docs Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Antd Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Element Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Naive Ftp (push) Has been cancelled
Release Drafter / update_release_draft (push) Has been cancelled
CI / CI OK (push) Has been cancelled
Deploy Website on push / Rerun on failure (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Issue Close Require / close-issues (push) Has been cancelled
Close stale issues / stale (push) Has been cancelled
75 lines
1.6 KiB
Vue
75 lines
1.6 KiB
Vue
<script lang="ts" setup>
|
|
import type { BreadcrumbStyleType } from '@vben/types';
|
|
|
|
import type { IBreadcrumb } from '@vben-core/shadcn-ui';
|
|
|
|
import { computed } from 'vue';
|
|
import { useRoute, useRouter } from 'vue-router';
|
|
|
|
import { $t } from '@vben/locales';
|
|
|
|
import { VbenBreadcrumbView } from '@vben-core/shadcn-ui';
|
|
|
|
interface Props {
|
|
hideWhenOnlyOne?: boolean;
|
|
showHome?: boolean;
|
|
showIcon?: boolean;
|
|
type?: BreadcrumbStyleType;
|
|
}
|
|
|
|
const props = withDefaults(defineProps<Props>(), {
|
|
showHome: false,
|
|
showIcon: false,
|
|
type: 'normal',
|
|
});
|
|
|
|
const route = useRoute();
|
|
const router = useRouter();
|
|
|
|
const breadcrumbs = computed((): IBreadcrumb[] => {
|
|
const matched = route.matched;
|
|
|
|
const resultBreadcrumb: IBreadcrumb[] = [];
|
|
|
|
for (const match of matched) {
|
|
const { meta, path } = match;
|
|
const { hideChildrenInMenu, hideInBreadcrumb, icon, name, title } =
|
|
meta || {};
|
|
if (hideInBreadcrumb || hideChildrenInMenu || !path) {
|
|
continue;
|
|
}
|
|
|
|
resultBreadcrumb.push({
|
|
icon,
|
|
path: path || route.path,
|
|
title: title ? $t((title || name) as string) : '',
|
|
});
|
|
}
|
|
if (props.showHome) {
|
|
resultBreadcrumb.unshift({
|
|
icon: 'mdi:home-outline',
|
|
isHome: true,
|
|
path: '/',
|
|
});
|
|
}
|
|
if (props.hideWhenOnlyOne && resultBreadcrumb.length === 1) {
|
|
return [];
|
|
}
|
|
|
|
return resultBreadcrumb;
|
|
});
|
|
|
|
function handleSelect(path: string) {
|
|
router.push(path);
|
|
}
|
|
</script>
|
|
<template>
|
|
<VbenBreadcrumbView
|
|
:breadcrumbs="breadcrumbs"
|
|
:show-icon="showIcon"
|
|
:style-type="type"
|
|
class="ml-2"
|
|
@select="handleSelect"
|
|
/>
|
|
</template>
|