增加悬浮窗功能
This commit is contained in:
@@ -14,5 +14,6 @@ export * from "./modules/settings";
|
||||
export * from "./modules/tags-view";
|
||||
export * from "./modules/user";
|
||||
export * from "./modules/dict";
|
||||
export * from "./modules/quick";
|
||||
|
||||
export { store };
|
||||
|
||||
@@ -16,6 +16,7 @@ export const usePermissionStore = defineStore("permission", () => {
|
||||
// 路由是否加载完成
|
||||
const isRoutesLoaded = ref(false);
|
||||
|
||||
const menus = ref<RouteVO[]>([])
|
||||
|
||||
|
||||
/**
|
||||
@@ -31,6 +32,7 @@ export const usePermissionStore = defineStore("permission", () => {
|
||||
}
|
||||
MenuAPI.getRoutes()
|
||||
.then((data) => {
|
||||
menus.value = data
|
||||
if (!isTest) {
|
||||
const dynamicRoutes = parseDynamicRoutes(data.filter(v => v.type == 0));
|
||||
dynamicRoutes.forEach((route) => {
|
||||
@@ -93,8 +95,60 @@ export const usePermissionStore = defineStore("permission", () => {
|
||||
});
|
||||
isRoutesLoaded.value = false;
|
||||
};
|
||||
function getMenuMap() {
|
||||
// 初始化Map
|
||||
const map = new Map();
|
||||
|
||||
// 定义递归函数处理菜单节点
|
||||
function processMenuNode(menuNode) {
|
||||
// 将当前节点存入Map
|
||||
map.set(menuNode.menuId, menuNode);
|
||||
|
||||
// 如果有子节点且子节点数组不为空,则递归处理每个子节点
|
||||
if (menuNode.children && Array.isArray(menuNode.children) && menuNode.children.length > 0) {
|
||||
menuNode.children.forEach((childNode) => {
|
||||
processMenuNode(childNode);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 遍历根级菜单,逐个处理
|
||||
if (menus.value && Array.isArray(menus.value)) {
|
||||
menus.value.forEach((rootMenu) => {
|
||||
processMenuNode(rootMenu);
|
||||
});
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
function returnMenuName(menuId: number | string) {
|
||||
const menu = menusIdMap.value.get(`${menuId}`);
|
||||
return menu ? menu.title : '';
|
||||
}
|
||||
const menusIdMap = computed(() => {
|
||||
const map = getMenuMap();
|
||||
return map;
|
||||
});
|
||||
|
||||
function menuJump(menuId: number | string) {
|
||||
const menu = menusIdMap.value.get(`${menuId}`);
|
||||
console.log('menu', menu);
|
||||
if (menu) {
|
||||
if (menu.name) {
|
||||
router.push({ name: menu.name as string })
|
||||
|
||||
} else {
|
||||
router.push({ path: menu.path as string })
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
menuJump,
|
||||
returnMenuName,
|
||||
menus,
|
||||
routes,
|
||||
mixedLayoutLeftRoutes,
|
||||
isRoutesLoaded,
|
||||
|
||||
37
src/store/modules/quick.ts
Normal file
37
src/store/modules/quick.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
import { store } from "@/store";
|
||||
import quickApi, { type QuickMenu } from "@/api/account/quick";
|
||||
import { usePermissionStoreHook } from "@/store/modules/permission";
|
||||
|
||||
|
||||
export const useQuickStore = defineStore("quick", () => {
|
||||
const quickMenus = ref<QuickMenu[]>([]);
|
||||
|
||||
async function getQuickMenus() {
|
||||
const res = await quickApi.getList({ isEdit: 0 });
|
||||
const obj: any = {}
|
||||
let arr = []
|
||||
for (let menu of res) {
|
||||
if (obj.hasOwnProperty(menu.menuId) || menu.status != 1 || !usePermissionStoreHook().returnMenuName(menu.menuId)) {
|
||||
continue;
|
||||
} else {
|
||||
obj[menu.menuId] = true;
|
||||
arr.push(menu)
|
||||
}
|
||||
}
|
||||
quickMenus.value = arr;
|
||||
}
|
||||
getQuickMenus()
|
||||
return {
|
||||
quickMenus, getQuickMenus
|
||||
};
|
||||
});
|
||||
|
||||
/**
|
||||
* 用于在组件外部(如在Pinia Store 中)使用 Pinia 提供的 store 实例。
|
||||
* 官方文档解释了如何在组件外部使用 Pinia Store:
|
||||
* https://pinia.vuejs.org/core-concepts/outside-component-usage.html#using-a-store-outside-of-a-component
|
||||
*/
|
||||
export function useQuickStoreHook() {
|
||||
return useQuickStore(store);
|
||||
}
|
||||
Reference in New Issue
Block a user