File size: 2,443 Bytes
8ede856
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<template>
    <v-breadcrumbs :items="computedItems" class="base-folder-breadcrumb pa-0">
        <template v-slot:prepend>
            <v-icon size="small" class="mr-1">mdi-folder-outline</v-icon>
        </template>
        <template v-slot:item="{ item }">
            <v-breadcrumbs-item :disabled="(item as any).disabled" @click="!(item as any).disabled && handleClick((item as any).folderId)"
                :class="{ 'breadcrumb-link': !(item as any).disabled }">
                <v-icon v-if="(item as any).isRoot" size="small" class="mr-1">mdi-home</v-icon>
                {{ (item as any).title }}
            </v-breadcrumbs-item>
        </template>
        <template v-slot:divider>
            <v-icon size="small">mdi-chevron-right</v-icon>
        </template>
    </v-breadcrumbs>
</template>

<script lang="ts">
import { defineComponent, type PropType } from 'vue';
import type { BreadcrumbItem, FolderTreeNode } from './types';

export default defineComponent({
    name: 'BaseFolderBreadcrumb',
    props: {
        breadcrumbPath: {
            type: Array as PropType<FolderTreeNode[]>,
            required: true
        },
        currentFolderId: {
            type: String as PropType<string | null>,
            default: null
        },
        rootFolderName: {
            type: String,
            default: '根目录'
        }
    },
    emits: ['navigate'],
    computed: {
        computedItems(): BreadcrumbItem[] {
            const items: BreadcrumbItem[] = [
                {
                    title: this.rootFolderName,
                    folderId: null,
                    disabled: this.currentFolderId === null,
                    isRoot: true
                }
            ];

            this.breadcrumbPath.forEach((folder, index) => {
                items.push({
                    title: folder.name,
                    folderId: folder.folder_id,
                    disabled: index === this.breadcrumbPath.length - 1,
                    isRoot: false
                });
            });

            return items;
        }
    },
    methods: {
        handleClick(folderId: string | null) {
            this.$emit('navigate', folderId);
        }
    }
});
</script>

<style scoped>
.base-folder-breadcrumb {
    font-size: 14px;
}

.breadcrumb-link {
    cursor: pointer;
    transition: color 0.2s;
}

.breadcrumb-link:hover {
    color: rgb(var(--v-theme-primary));
}
</style>