zhangxiao
2024-08-20 e47b788ff5f5c699c682999c95da17eb284ca21d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<template>
    <div class="app-bread-list">
        <a-breadcrumb>
            <a-breadcrumb-item v-for="(item, index) in breadList" :key="item.name">
                <div class="bre-item">
                    <Svg v-if="item.meta?.icon" :name="String(item.meta.icon)" :width="20" :height="20"></Svg>
                    <div v-if="checkDidsable(item, index)">{{ $t(item.meta.title) }}</div>
                    <a-link v-else @click="onClick(item)"> {{ $t(item.meta.title) }}</a-link>
                </div>
            </a-breadcrumb-item>
        </a-breadcrumb>
    </div>
</template>
<script lang="ts" setup>
import router, { getRouteParent } from "@/packages/vue-router/index";
import { Svg } from "@easyfe/admin-component";
import { RouteLocationMatched } from "vue-router";
const breadList = computed(() => {
    return getRouteParent();
});
 
function checkDidsable(item: RouteLocationMatched, index: number) {
    if (index === breadList.value.length - 1) {
        return true;
    }
    if (!item.children?.length) {
        return false;
    }
    //如果子路由全部都是隐藏的,则认为没有子路由
    const hideRouters = item.children.filter((v: any) => v.meta?.hidden === true || v.meta?.permission?.() === false);
    if (hideRouters.length === item.children.length) {
        return false;
    }
    return true;
}
 
const onClick = (item: RouteLocationMatched) => {
    router.push(item);
};
</script>
<style lang="scss" scoped>
.app-bread-list {
    user-select: none;
    .arco-breadcrumb-item a:hover {
        color: $main;
    }
    .bre-item {
        display: flex;
        align-items: center;
        .svg-icon {
            margin-right: 4px;
        }
    }
}
</style>