2024-07-13 16:35:47 +08:00
|
|
|
|
import type {
|
2025-04-23 12:56:35 +08:00
|
|
|
|
AppRouteRecordRaw,
|
2024-07-13 16:35:47 +08:00
|
|
|
|
ComponentRecordType,
|
|
|
|
|
|
GenerateMenuAndRoutesOptions,
|
|
|
|
|
|
} from '@vben/types';
|
2024-06-30 15:03:37 +08:00
|
|
|
|
|
2024-07-13 16:35:47 +08:00
|
|
|
|
import { generateAccessible } from '@vben/access';
|
2024-07-23 00:03:59 +08:00
|
|
|
|
import { preferences } from '@vben/preferences';
|
2025-03-20 12:34:02 +08:00
|
|
|
|
import { useAccessStore } from '@vben/stores';
|
|
|
|
|
|
import { convertServerMenuToRouteRecordStringComponent } from '@vben/utils';
|
2024-06-30 15:03:37 +08:00
|
|
|
|
|
2025-04-22 22:17:41 +08:00
|
|
|
|
import { BasicLayout, IFrameView } from '#/layouts';
|
|
|
|
|
|
|
2024-07-13 16:52:08 +08:00
|
|
|
|
const forbiddenComponent = () => import('#/views/_core/fallback/forbidden.vue');
|
2024-06-30 15:03:37 +08:00
|
|
|
|
|
2024-07-13 16:35:47 +08:00
|
|
|
|
async function generateAccess(options: GenerateMenuAndRoutesOptions) {
|
2024-06-30 15:03:37 +08:00
|
|
|
|
const pageMap: ComponentRecordType = import.meta.glob('../views/**/*.vue');
|
2025-03-20 12:34:02 +08:00
|
|
|
|
const accessStore = useAccessStore();
|
2024-06-30 15:03:37 +08:00
|
|
|
|
|
|
|
|
|
|
const layoutMap: ComponentRecordType = {
|
|
|
|
|
|
BasicLayout,
|
|
|
|
|
|
IFrameView,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-07-13 16:35:47 +08:00
|
|
|
|
return await generateAccessible(preferences.app.accessMode, {
|
2024-06-30 15:03:37 +08:00
|
|
|
|
...options,
|
|
|
|
|
|
fetchMenuListAsync: async () => {
|
2025-03-20 12:34:02 +08:00
|
|
|
|
// 由于 yudao 通过 accessStore 读取,所以不在进行 message.loading 提示
|
2025-04-23 12:56:35 +08:00
|
|
|
|
// 补充说明:accessStore.accessMenus 一开始是 AppRouteRecordRaw 类型(后端加载),后面被赋值成 MenuRecordRaw 类型(前端转换)
|
|
|
|
|
|
const accessMenus = accessStore.accessMenus as AppRouteRecordRaw[];
|
2025-03-20 12:34:02 +08:00
|
|
|
|
return convertServerMenuToRouteRecordStringComponent(accessMenus);
|
2024-06-30 15:03:37 +08:00
|
|
|
|
},
|
|
|
|
|
|
// 可以指定没有权限跳转403页面
|
2024-07-10 21:20:11 +08:00
|
|
|
|
forbiddenComponent,
|
2024-06-30 15:03:37 +08:00
|
|
|
|
// 如果 route.meta.menuVisibleWithForbidden = true
|
|
|
|
|
|
layoutMap,
|
|
|
|
|
|
pageMap,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export { generateAccess };
|