import { DEFAULT_APP_NAME } from '../constants'; import { getListFromTree, getTreeFromList } from './tree'; import { sessionStore } from './store'; import { pathHolder } from './route'; import { getAppSelections, getButtonList, getMenuList } from '../services'; export async function getAppIdHolder() { const appList = await getAppSelections(); const { appId } = appList.find((item) => item.appNameEn === DEFAULT_APP_NAME) || {}; return appId; } export async function getMenuHolder( appId: string, roleId: string, groupName: string, ) { let _menuList = await getMenuList(appId, roleId); if (groupName) { const { children } = (_menuList || []).find((item) => item.menuName === groupName) || {}; _menuList = children || []; } const menuList = getListFromTree(_menuList || []).map((item) => { const { menuName: name, menuId: key, path: _path, icon, parentId } = item; const path = pathHolder(_path); return { name, key, path, icon, parentId, }; }); const menuTreeList = getTreeFromList(menuList, { idKey: 'key', parentIdKey: 'parentId', }); const authorizedRouteList = menuList .filter((item) => item.path) .map(({ path, name }) => { return { path, name }; }); sessionStore.set('menu-original-list', _menuList); sessionStore.set('menu-pure-list', menuList); sessionStore.set('menu-tree-list', menuTreeList); sessionStore.set('authorized-route-list', authorizedRouteList); return _menuList; } export async function getButtonHolder(appId: string, roleId: string) { const buttonList = await getButtonList(appId, roleId); sessionStore.set('button-list', buttonList); return buttonList; }