-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
90 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<template> | ||
<el-breadcrumb class="app-breadcrumb" separator="/"> | ||
<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> | ||
</el-breadcrumb> | ||
</template> | ||
|
||
<script setup> | ||
// import { compile } from "path-to-regexp"; | ||
import { reactive, ref, watch } from "vue"; | ||
import { useRoute, useRouter } from "vue-router"; | ||
const levelList = ref(null); | ||
const router = useRouter(); | ||
// 当前路由 | ||
const route = useRoute(); | ||
// 解析路由匹配的数组 | ||
const getBreadcrumb = () => { | ||
// 过滤留下只有meta和title | ||
let matched = route.matched.filter((item) => item.meta && item.meta.title); | ||
// 拼出最终需要展示的跳转数据 | ||
levelList.value = matched.filter( | ||
(item) => item.meta && item.meta.title && item.meta.breadcrumb !== false | ||
); | ||
}; | ||
// 手动解析path中可能存在的参数 | ||
const pathCompile = (path) => { | ||
// var toPath = compile(path); | ||
console.log(path) | ||
var toPath = path; | ||
return toPath(route.params); | ||
}; | ||
// 跳转连接处理 | ||
const handleLink = (item) => { | ||
const { redirect, path } = item; | ||
if (redirect) { | ||
router.push(redirect); | ||
return; | ||
} | ||
router.push(pathCompile(path)); | ||
}; | ||
// 首次调用 | ||
getBreadcrumb(); | ||
// 监控route的变化,避免组件复用信息同步问题 | ||
watch(route, getBreadcrumb); | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
@import "@/styles/variables.module.scss"; | ||
.app-breadcrumb.el-breadcrumb { | ||
// display: inline-block; | ||
// font-size: 14px; | ||
line-height: #{$BreadcrumbHeight}; | ||
// margin-left: 8px; | ||
.no-redirect { | ||
color: #97a8be; | ||
cursor: text; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters