Files
cutejava/cutejava-front/src/components/Breadcrumb/index.vue
T
odboy 77abc7b0e2 style(styles): 添加导航栏面包屑汉堡菜单样式变量并应用
- 在 variables.technology3.scss 中添加 Navbar 顶部导航栏样式变量
- 在 variables.technology3.scss 中添加 Hamburger 汉堡菜单按钮样式变量
- 在 variables.technology3.scss 中添加 Breadcrumb 面包屑导航样式变量
- 在 Breadcrumb 组件中应用新的面包屑样式变量
- 在 Hamburger 组件中应用新的汉堡菜单样式变量
- 在 Navbar 组件中应用新的导航栏样式变量
- 移除 Breadcrumb 组件中对 variables.technology3 的重复导入
2026-01-25 09:29:14 +08:00

127 lines
3.2 KiB
Vue

<template>
<el-breadcrumb class="app-breadcrumb" separator="/">
<transition-group name="breadcrumb">
<el-breadcrumb-item v-for="(item,index) in levelList" :key="item.path">
<span v-if="item.redirect==='noredirect'||index==levelList.length-1" class="no-redirect">{{
item.meta.title
}}</span>
<a v-else @click.prevent="handleLink(item)">{{ item.meta.title }}</a>
</el-breadcrumb-item>
</transition-group>
</el-breadcrumb>
</template>
<script>
import pathToRegexp from 'path-to-regexp'
export default {
data() {
return {
levelList: null
}
},
watch: {
$route(route) {
// if you go to the redirect page, do not update the breadcrumbs
if (route.path.startsWith('/redirect/')) {
return
}
this.getBreadcrumb()
}
},
created() {
this.getBreadcrumb()
},
methods: {
getBreadcrumb() {
// only show routes with meta.title
let matched = this.$route.matched.filter(item => item.meta && item.meta.title)
const first = matched[0]
if (!this.isDashboard(first)) {
matched = [{ path: '/dashboard', meta: { title: '首页' }}].concat(matched)
}
this.levelList = matched.filter(item => item.meta && item.meta.title && item.meta.breadcrumb !== false)
},
isDashboard(route) {
const name = route && route.name
if (!name) {
return false
}
return name.trim().toLocaleLowerCase() === 'Dashboard'.toLocaleLowerCase()
},
pathCompile(path) {
// To solve this problem https://github.com/PanJiaChen/vue-element-admin/issues/561
const { params } = this.$route
var toPath = pathToRegexp.compile(path)
return toPath(params)
},
handleLink(item) {
const { redirect, path } = item
if (redirect) {
this.$router.push(redirect)
return
}
this.$router.push(this.pathCompile(path))
}
}
}
</script>
<style lang="scss" scoped>
@import "~@/assets/styles/variables";
.app-breadcrumb.el-breadcrumb {
display: inline-block;
font-size: 14px;
line-height: 50px;
margin-left: 8px;
::v-deep .el-breadcrumb__item {
.el-breadcrumb__inner {
color: $breadcrumbTextColor !important;
font-weight: 500;
transition: all 0.3s ease;
&.is-link {
color: $breadcrumbLinkColor !important;
text-shadow: 0 0 4px $breadcrumbTextGlow;
&:hover {
color: $breadcrumbHoverColor !important;
filter: drop-shadow($breadcrumbHoverGlow);
}
}
&:hover {
color: $breadcrumbHoverColor !important;
filter: drop-shadow($breadcrumbHoverGlow);
}
}
.el-breadcrumb__separator {
color: $breadcrumbSeparatorColor;
}
}
a {
color: $breadcrumbLinkColor !important;
font-weight: 500;
text-shadow: 0 0 4px $breadcrumbTextGlow;
&:hover {
color: $breadcrumbHoverColor !important;
filter: drop-shadow($breadcrumbHoverGlow);
}
}
.no-redirect {
color: $breadcrumbNoRedirectColor !important;
cursor: text;
font-weight: 500;
text-shadow: 0 0 4px $breadcrumbTextGlow;
}
}
</style>