perf: 面包屑去首页化,根据选择的菜单对应显示,首页不在固定到面包屑里,并优化面包屑页面的路由监听

This commit is contained in:
xiaoxian521 2023-05-09 15:28:53 +08:00
parent 4bc888b273
commit d4de5fc6f6

View File

@ -1,6 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { isEqual } from "@pureadmin/utils"; import { isEqual } from "@pureadmin/utils";
import { routerArrays } from "@/layout/types";
import { transformI18n } from "@/plugins/i18n"; import { transformI18n } from "@/plugins/i18n";
import { ref, watch, onMounted, toRaw } from "vue"; import { ref, watch, onMounted, toRaw } from "vue";
import { getParentPaths, findRouteByPath } from "@/router/utils"; import { getParentPaths, findRouteByPath } from "@/router/utils";
@ -11,7 +10,6 @@ const route = useRoute();
const levelList = ref([]); const levelList = ref([]);
const router = useRouter(); const router = useRouter();
const routes: any = router.options.routes; const routes: any = router.options.routes;
const { VITE_HIDE_HOME } = import.meta.env;
const multiTags: any = useMultiTagsStoreHook().multiTags; const multiTags: any = useMultiTagsStoreHook().multiTags;
const getBreadcrumb = (): void => { const getBreadcrumb = (): void => {
@ -33,6 +31,7 @@ const getBreadcrumb = (): void => {
} else { } else {
currentRoute = findRouteByPath(router.currentRoute.value.path, routes); currentRoute = findRouteByPath(router.currentRoute.value.path, routes);
} }
// //
const parentRoutes = getParentPaths( const parentRoutes = getParentPaths(
router.currentRoute.value.name as string, router.currentRoute.value.name as string,
@ -40,16 +39,14 @@ const getBreadcrumb = (): void => {
"name" "name"
); );
// //
let matched = []; const matched = [];
// //
parentRoutes.forEach(path => { parentRoutes.forEach(path => {
if (path !== "/") matched.push(findRouteByPath(path, routes)); if (path !== "/") matched.push(findRouteByPath(path, routes));
}); });
if (currentRoute?.path !== "/welcome") matched.push(currentRoute); matched.push(currentRoute);
if (VITE_HIDE_HOME === "false") matched = routerArrays.concat(matched);
matched.forEach((item, index) => { matched.forEach((item, index) => {
if (currentRoute?.query || currentRoute?.params) return; if (currentRoute?.query || currentRoute?.params) return;
@ -84,6 +81,9 @@ watch(
() => route.path, () => route.path,
() => { () => {
getBreadcrumb(); getBreadcrumb();
},
{
deep: true
} }
); );
</script> </script>