w-vue-middle
Version:
统一公共服务组件
140 lines (130 loc) • 4.42 kB
JavaScript
/*
* @Author: Jason Liu
* @Date: 2022-11-18 10:44:46
* @Desc:
*/
/**
* @Author: Jason Liu
* @description: 获取启动的应用
*/
export function getUseApp($route, apps = []) {
let activeMenu = undefined; //标识选中菜单
//一级菜单过滤内容
let useapp = apps.find((item) => {
let has = $route.path == item.path;
if (!has && item.menus) {
has = item.menus.find((sub) => {
if ($route.path == sub.path) {
return true;
} else if (sub.menus) {
return !!sub.menus.find(chid => { return $route.path == chid.path });
} else {
return false;
}
});
}
return has;
});
let children = []; //子集菜单
let menus = [];
if (useapp) {
activeMenu = { name: useapp.name, path: useapp.path, title: useapp.title };
menus = useapp.menus.filter(app => {
if (app.menu && app.menu.menuType) {
return app.menu.menuType == "C";//菜单
} else {
return true;
}
}).map((item) => {
if ($route.path == item.path) {
activeMenu = item;
}
return item;
});
} else {
useapp = {
name: undefined,
path: undefined,
menus: []
}
}
const getMenu = (parentId = undefined) => {
return menus
.filter((item, i) => {
if (item.parentId == parentId) {
return true;
} else {
return false;
}
})
.sort((o, l) => {
return o.orderNum - l.orderNum;
});
};
children = getMenu();
return {
name: useapp.name,
active: activeMenu,
children: children,
};
};
/**
* @Author: Jason Liu
* @description: 根据路由信息,解析菜单
*/
export function getAppsByRouter(routers, parentId = undefined) {
if (routers) {
const Disable = $storage.get("SYS_Authority_Disable");
if (Disable == "false") {
//禁用权限设置
return routers.map((router) => {
const children = getAppsByRouter(router.children);
return {
name: router.name,
title: router.meta ? router.meta.title : undefined,
path: router.path,
appId: router.name,
menuMapId: router.name,
icon: router.meta ? router.meta.icon : undefined,
parentId: parentId,
menus: children,
children: children
};
});
} else {
const apps = $storage.get("STSTEM_INFO").toJson([]);
const activeApp = apps.find(app => { return app.app.appUuid == $service.uuid })
if (activeApp) {
const menus = activeApp.menus.filter(app => {
return app.menu.menuType == "C";//菜单
});
const getChildren = (pid) => {
return menus.filter(app => { return app.menu.parentId == pid }).map(app => {
const thisChildren = getChildren(app.menu.menuMapId);
return {
...app.menu,
menus: thisChildren,
children: thisChildren
};
});
}
const children = getChildren();
return [{
name: activeApp.app.appName,
title: activeApp.app.appName,
path: `/${activeApp.app.appKey}`,
appId: activeApp.app.appKey,
menuMapId: activeApp.app.appKey,
icon: undefined,
parentId: undefined,
menus: children,
children: children
}]
} else {
return undefined
}
}
} else {
return undefined;
}
};