| | |
| | | import { convertServerMenuToRouteRecordStringComponent } from '@vben/utils'; |
| | | |
| | | import { BasicLayout, IFrameView } from '#/layouts'; |
| | | import { isAiFeatureEnabled } from '#/utils/features'; |
| | | |
| | | const forbiddenComponent = () => import('#/views/_core/fallback/forbidden.vue'); |
| | | |
| | | function isAiRoute(route: AppRouteRecordRaw) { |
| | | const path = String(route.path || '').toLowerCase(); |
| | | const component = String(route.component || '').toLowerCase(); |
| | | return ( |
| | | path === '/ai' || |
| | | path.startsWith('/ai/') || |
| | | component.startsWith('ai/') || |
| | | component.includes('/views/ai/') |
| | | ); |
| | | } |
| | | |
| | | function filterDisabledAiRoutes(routes: AppRouteRecordRaw[]): AppRouteRecordRaw[] { |
| | | if (isAiFeatureEnabled) { |
| | | return routes; |
| | | } |
| | | return routes |
| | | .filter((route) => !isAiRoute(route)) |
| | | .map((route) => ({ |
| | | ...route, |
| | | children: route.children |
| | | ? filterDisabledAiRoutes(route.children as AppRouteRecordRaw[]) |
| | | : route.children, |
| | | })); |
| | | } |
| | | |
| | | async function generateAccess(options: GenerateMenuAndRoutesOptions) { |
| | | const pageMap: ComponentRecordType = import.meta.glob('../views/**/*.vue'); |
| | |
| | | fetchMenuListAsync: async () => { |
| | | // 由于 yudao 通过 accessStore 读取,所以不在进行 message.loading 提示 |
| | | // 补充说明:accessStore.accessMenus 一开始是 AppRouteRecordRaw 类型(后端加载),后面被赋值成 MenuRecordRaw 类型(前端转换) |
| | | const accessMenus = accessStore.accessMenus as AppRouteRecordRaw[]; |
| | | const accessMenus = filterDisabledAiRoutes( |
| | | accessStore.accessMenus as AppRouteRecordRaw[], |
| | | ); |
| | | return convertServerMenuToRouteRecordStringComponent(accessMenus); |
| | | }, |
| | | // 可以指定没有权限跳转403页面 |