From 65d03dc0145afe034b72759e0db78c69c12d584e Mon Sep 17 00:00:00 2001
From: RuoYi <yzz_ivy@163.com>
Date: Mon, 25 Nov 2024 22:30:03 +0800
Subject: [PATCH] 优化代码

---
 ruoyi-ui/src/components/Breadcrumb/index.vue |   19 +++++++++++--------
 1 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/ruoyi-ui/src/components/Breadcrumb/index.vue b/ruoyi-ui/src/components/Breadcrumb/index.vue
index c97e59d..cd28414 100644
--- a/ruoyi-ui/src/components/Breadcrumb/index.vue
+++ b/ruoyi-ui/src/components/Breadcrumb/index.vue
@@ -41,14 +41,15 @@
           if (index !== 0) item = item.slice(1)
           return item
         })
-        this.getMatched(pathList, this.$store.getters.sidebarRouters, matched)
+        this.getMatched(pathList, this.$store.getters.defaultRoutes, matched)
       } else {
-        matched = router.matched.filter((item) => item.meta && item.meta.title)
+        matched = router.matched.filter(item => item.meta && item.meta.title)
       }
+      // 判断是否为首页
       if (!this.isDashboard(matched[0])) {
         matched = [{ path: "/index", meta: { title: "首页" } }].concat(matched)
       }
-      this.levelList = matched.filter((item) => item.meta && item.meta.title && item.meta.breadcrumb !== false)
+      this.levelList = matched.filter(item => item.meta && item.meta.title && item.meta.breadcrumb !== false)
     },
     findPathNum(str, char = "/") {
       let index = str.indexOf(char)
@@ -60,11 +61,13 @@
       return num
     },
     getMatched(pathList, routeList, matched) {
-      let data = routeList.find((item) => item.path == pathList[0])
-      matched.push(data)
-      if (data.children && pathList.length) {
-        pathList.shift()
-        this.getMatched(pathList, data.children, matched)
+      let data = routeList.find(item => item.path == pathList[0] || (item.name += '').toLowerCase() == pathList[0])
+      if (data) {
+        matched.push(data)
+        if (data.children && pathList.length) {
+          pathList.shift()
+          this.getMatched(pathList, data.children, matched)
+        }
       }
     },
     isDashboard(route) {

--
Gitblit v1.9.3