| | |
| | | // import { RouteConfigs } from "@/layout/types"; |
| | | import { constantRoutes, Route } from '@/router'; |
| | | import { addAsyncRoutes, ascending } from '@/router/utils'; |
| | | import * as menuServices from '@/services/api/menu'; |
| | | |
| | | export interface PermissonState { |
| | | routes: Route[]; |
| | |
| | | getModuleList() { |
| | | return new Promise<Route[]>(async (resolve, reject) => { |
| | | try { |
| | | // const res = await baseModuleServices.getCurrentUserModuleList({ |
| | | // showLoading: false, |
| | | // }); |
| | | const res = []; |
| | | const accessedRoutes = ascending(addAsyncRoutes(formatModuleList(res, null))); // createAccessedRoutes(userMenuList, userInfo) |
| | | const res = await menuServices.getMenus( |
| | | { |
| | | userType: EnumUserType.Operation, |
| | | clientType: EnumClientType.PcWeb, |
| | | }, |
| | | { |
| | | showLoading: false, |
| | | } |
| | | ); |
| | | const accessedRoutes = ascending(addAsyncRoutes(formatModuleList(res))); // createAccessedRoutes(userMenuList, userInfo) |
| | | //@ts-ignore |
| | | accessedRoutes.push({ path: '/:pathMatch(.*)*', redirect: '/404', hidden: true }); |
| | | |
| | |
| | | return usePermissionStore(store); |
| | | } |
| | | |
| | | function formatModuleList(moduleList: API.ModuleDto[], parentId: string | null) { |
| | | const treeModuleList: Route[] = []; |
| | | if (moduleList.length > 0) { |
| | | moduleList.forEach((item) => { |
| | | if (item.parentId === parentId) { |
| | | const isRootModule = !item.parentId && item.isMenu === 1; |
| | | function formatModuleList(moduleList: API.GetMenusQueryResultItem[]) { |
| | | return moduleList.map((item) => { |
| | | const isRootModule = !item.parentId && item.type == EnumMenuType.Menu; |
| | | //@ts-ignore |
| | | const asyncRoute: Route = isRootModule |
| | | let asyncRoute: Route = isRootModule |
| | | ? { |
| | | path: formatPath(item.path), |
| | | name: item.enCode, |
| | | path: formatPath(item.url), |
| | | name: item.code, |
| | | redirect: 'noRedirect', |
| | | alwaysShow: true, |
| | | hidden: item.isMenu !== 1, |
| | | hidden: item.type != EnumMenuType.Menu, |
| | | meta: { |
| | | title: item.name, |
| | | icon: item.icon, |
| | | moduleId: item.id, |
| | | rank: item?.sortCode, |
| | | rank: item?.sort, |
| | | rootMenu: true, |
| | | }, |
| | | } |
| | | : { |
| | | path: formatPath(item.path), |
| | | name: item.enCode, |
| | | hidden: item.isMenu !== 1, |
| | | path: formatPath(item.url), |
| | | name: item.code, |
| | | hidden: item.type != EnumMenuType.Menu, |
| | | alwaysShow: true, |
| | | meta: { |
| | | title: item.name, |
| | | moduleId: item.id, |
| | | noCache: !item.isCache, |
| | | rank: item?.sortCode, |
| | | rank: item?.sort, |
| | | }, |
| | | }; |
| | | const children = formatModuleList(moduleList, item.id); |
| | | const children = formatModuleList(item.children); |
| | | asyncRoute.children = children; |
| | | treeModuleList.push(asyncRoute); |
| | | } |
| | | return asyncRoute; |
| | | }); |
| | | } |
| | | return treeModuleList; |
| | | } |
| | | |
| | | function formatPath(path: string) { |