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

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

View File

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