mirror of
https://github.com/cool-team-official/cool-admin-vue.git
synced 2025-12-14 14:52:49 +00:00
解决顶部菜单无法跳转问题
This commit is contained in:
parent
dfb576bee3
commit
fc87f8c519
@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
@ -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 || "/";
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user