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