解决顶部菜单无法跳转问题

This commit is contained in:
icssoa 2023-03-09 15:01:37 +08:00
parent dfb576bee3
commit fc87f8c519
2 changed files with 26 additions and 19 deletions

View File

@ -18,6 +18,7 @@
import { onMounted, ref } from "vue";
import { useBase } from "/$/base";
import { useCool } from "/@/cool";
import { Menu } from "../../types";
const { router, route } = useCool();
const { menu } = useBase();
@ -26,20 +27,20 @@ const { menu } = useBase();
const active = ref("");
//
function select(index: any) {
function select(index: number) {
menu.setMenu(index);
//
const url = menu.getPath(menu.group[index].children);
const url = menu.getPath(menu.group[index]);
router.push(url);
}
onMounted(function () {
//
function deep(e: any, i: number) {
function deep(e: Menu.Item, i: number) {
switch (e.type) {
case 0:
e.children.forEach((e: any) => {
(e.children || []).forEach((e) => {
deep(e, i);
});
break;
@ -55,7 +56,7 @@ onMounted(function () {
}
}
menu.group.forEach((e: any, i: number) => {
menu.group.forEach((e, i) => {
deep(e, i);
});
});

View File

@ -136,24 +136,30 @@ export const useMenuStore = defineStore("menu", function () {
}
// 获取菜单路径
function getPath(list?: Menu.List) {
list = list || group.value;
function getPath(item?: Menu.Item) {
let path = "";
function deep(arr: Menu.List) {
arr.forEach((e: Menu.Item) => {
if (e.type == 1) {
if (!path) {
path = e.path;
}
} else {
deep(e.children || []);
switch (item?.type) {
case 0:
function deep(arr: Menu.List) {
arr.forEach((e: Menu.Item) => {
if (e.type == 1) {
if (!path) {
path = e.path;
}
} else {
deep(e.children || []);
}
});
}
});
}
deep(list);
deep(item.children || group.value || []);
break;
case 1:
path = item.path;
break;
}
return path || "/";
}