|
|
@ -1,7 +1,7 @@ |
|
|
|
<script setup> |
|
|
|
// 导航栏在这 |
|
|
|
import {ref} from 'vue' |
|
|
|
import {useRouter} from 'vue-router' |
|
|
|
import {computed, ref} from 'vue' |
|
|
|
import {useRoute, useRouter} from 'vue-router' |
|
|
|
import {ElMessage} from 'element-plus' |
|
|
|
import dmmn from '../assets/link.png' |
|
|
|
import ChangePassword from '@/components/changePassword.vue' |
|
|
@ -21,7 +21,35 @@ const {adminData, menuTree} = storeToRefs(adminStore) |
|
|
|
menuList.value = filterMenu(menuTree.value) |
|
|
|
|
|
|
|
console.log("menuList", menuList.value) |
|
|
|
// 获取当前路由 |
|
|
|
const route = useRoute() |
|
|
|
|
|
|
|
// 通用函数:从菜单树中递归找出最匹配的 index |
|
|
|
function findBestMatch(menuList, path) { |
|
|
|
let bestMatch = '' |
|
|
|
|
|
|
|
function traverse(menus) { |
|
|
|
for (const item of menus) { |
|
|
|
const itemPath = getRoutePath(item) |
|
|
|
// 如果当前菜单的 path 是当前路径的前缀,可能是候选项 |
|
|
|
if (path.startsWith(itemPath) && itemPath.length > bestMatch.length) { |
|
|
|
bestMatch = itemPath |
|
|
|
} |
|
|
|
|
|
|
|
if (item.children && item.children.length > 0) { |
|
|
|
traverse(item.children) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
traverse(menuList) |
|
|
|
return bestMatch || path // fallback 到当前路径 |
|
|
|
} |
|
|
|
|
|
|
|
// 响应式高亮菜单 |
|
|
|
const activeMenu = computed(() => { |
|
|
|
return findBestMatch(menuList.value, route.path) |
|
|
|
}) |
|
|
|
const router = useRouter() |
|
|
|
const imgrule1 = dmmn |
|
|
|
const messageVisible = ref(false) |
|
|
@ -81,7 +109,7 @@ function logout() { |
|
|
|
<el-menu |
|
|
|
:router="true" |
|
|
|
class="el-menu-vertical-demo" |
|
|
|
:default-active="$route.path" |
|
|
|
:default-active="activeMenu" |
|
|
|
> |
|
|
|
<!-- 递归渲染菜单层级 --> |
|
|
|
<template v-for="menu in menuList" :key="menu.id"> |
|
|
|