import { defineStore } from 'pinia';import { store } from '/@/store';import { useI18n } from '/@/hooks/web/useI18n';import { useUserStore } from './user';import { useAppStoreWidthOut } from './app';
const { t } = useI18n(); const userStore = useUserStore(); const appStore = useAppStoreWidthOut(); let routes: AppRouteRecordRaw[] = []; const roleList = toRaw(userStore.getRoleList); const { permissionMode = projectSetting.permissionMode } = appStore.getProjectConfig; // role permissions if (permissionMode === PermissionModeEnum.ROLE) { const routeFilter = (route: AppRouteRecordRaw) => { const { meta } = route; const { roles } = meta || {}; if (!roles) return true; return roleList.some((role) => roles.includes(role)); }; routes = filter(asyncRoutes, routeFilter); routes = routes.filter(routeFilter); // Convert multi-level routing to level 2 routing routes = flatMultiLevelRoutes(routes); // If you are sure that you do not need to do background dynamic permissions, please comment the entire judgment below } else if (permissionMode === PermissionModeEnum.BACK) { const { createMessage } = useMessage(); createMessage.loading({ content: t('sys.app.menuLoading'), duration: 1, }); // !Simulate to obtain permission codes from the background, // this function may only need to be executed once, and the actual project can be put at the right time by itself
routes.push(ERROR_LOG_ROUTE); return routes; }, },});// Need to be used outside the setupexport function usePermissionStoreWidthOut() { return usePermissionStore(store);