瀏覽代碼

三级菜单路径选择

zhengnaiwen_citu 6 月之前
父節點
當前提交
6140b5c37b
共有 1 個文件被更改,包括 12 次插入5 次删除
  1. 12 5
      src/layout/enterprise.vue

+ 12 - 5
src/layout/enterprise.vue

@@ -61,11 +61,17 @@ const isInWhiteList = (url, whiteList)=> {
 }
 }
 
 
 const breadcrumbs = ref([])
 const breadcrumbs = ref([])
-const getTitle = (list) => {
+const getTitle = (list, fullPath) => {
+  const _fullPath = fullPath.split('/')
   const arr = list.map((item, index) => {
   const arr = list.map((item, index) => {
+    // 重组路径
     if (item.path === list[index - 1]?.path) return false
     if (item.path === list[index - 1]?.path) return false
     const text = item.meta.title
     const text = item.meta.title
-    const obj = { text,  to: item.path }
+    const _path = item.path.split('/')
+    const obj = {
+      text,
+      to: _path.map((e, i) => _fullPath[i]).join('/')
+    }
     return obj
     return obj
   }).filter(e => e) || []
   }).filter(e => e) || []
   if (arr?.length) {
   if (arr?.length) {
@@ -77,14 +83,15 @@ const getTitle = (list) => {
 
 
 watch(
 watch(
   () => route.matched,
   () => route.matched,
-  (val) => {
-    getTitle(val)
+  (val) => {    
+    getTitle(val, route.fullPath)
   },
   },
   { immediate: true },
   { immediate: true },
   { deep: true }
   { deep: true }
 )
 )
 
 
-const toPath = ({ disabled, to }) => {
+const toPath = (item) => {
+  const { disabled, to } = item
   if (disabled) {
   if (disabled) {
     event.preventDefault()
     event.preventDefault()
     return
     return