2024-07-13 16:35:47 +08:00
|
|
|
import type {
|
|
|
|
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-06-30 15:03:37 +08:00
|
|
|
import { preferences } from '@vben-core/preferences';
|
|
|
|
|
|
|
|
import { message } from 'ant-design-vue';
|
|
|
|
|
|
|
|
import { getAllMenus } from '#/apis';
|
|
|
|
import { BasicLayout, IFrameView } from '#/layouts';
|
2024-07-07 00:17:44 +08:00
|
|
|
import { $t } from '#/locales';
|
2024-06-30 15:03:37 +08:00
|
|
|
|
2024-07-10 21:20:11 +08:00
|
|
|
const forbiddenComponent = () =>
|
|
|
|
import('#/views/_essential/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');
|
|
|
|
|
|
|
|
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 () => {
|
|
|
|
message.loading({
|
2024-07-10 21:55:16 +08:00
|
|
|
content: `${$t('common.loadingMenu')}...`,
|
2024-06-30 15:03:37 +08:00
|
|
|
duration: 1.5,
|
|
|
|
});
|
|
|
|
return await getAllMenus();
|
|
|
|
},
|
|
|
|
// 可以指定没有权限跳转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 };
|