index.vue 1.44 KB
<template>
  <a-breadcrumb class="container-breadcrumb">
    <a-breadcrumb-item>
      <icon-apps />
    </a-breadcrumb-item>
    <a-breadcrumb-item v-for="item in items" :key="item">
      <router-link v-if="getRouteMeta(item)?.isRedirect" :to="{ name: item }">
        {{ getRouteName(item) }}
      </router-link>
      <span v-else> {{ getRouteName(item) }}</span>
    </a-breadcrumb-item>
  </a-breadcrumb>
</template>

<script lang="ts" setup>
import { IconApps } from '@arco-design/web-vue/es/icon';
import { computed } from 'vue';
import { RouteMeta, RouteRecordNormalized, useRouter } from 'vue-router';
import { useAppStore } from '@/store';
import { storeToRefs } from 'pinia';

defineProps<{ items: string[] }>();

const router = useRouter();
const appStore = useAppStore();

const { appMenu } = storeToRefs(appStore);

const routes = computed(() => {
  return router.getRoutes() as RouteRecordNormalized[];
});

const getRoute = (name: any) => {
  return routes.value.find((el) => el.name === name);
};

const getRouteMeta = (name: any): RouteMeta | undefined => {
  return getRoute(name)?.meta;
};

const getRouteName = (name: any) => {
  return getRouteMeta(name)?.title || appMenu.value.find((item) => item.name === name)?.label || '';
};
</script>

<style lang="less" scoped>
.container-breadcrumb {
  margin: 16px 0;

  :deep(.arco-breadcrumb-item) {
    color: rgb(var(--gray-6));

    &:last-child {
      color: rgb(var(--gray-8));
    }
  }
}
</style>