ruoyi-plus-soybean/src/utils/router/component.ts

35 lines
1.2 KiB
TypeScript
Raw Normal View History

import type { Component } from 'vue';
import { EnumLayoutComponentName } from '@/enum';
import { BasicLayout, BlankLayout } from '@/layouts';
import { views } from '@/views';
import type { LayoutComponentName } from '@/interface';
type LayoutComponent = Record<LayoutComponentName, () => Promise<Component>>;
/**
* vue文件()
* @param layoutType -
*/
export function getLayoutComponent(layoutType: LayoutComponentName) {
const layoutComponent: LayoutComponent = {
basic: BasicLayout,
blank: BlankLayout,
};
return () => setViewComponentName(layoutComponent[layoutType], EnumLayoutComponentName[layoutType]);
}
/**
* vue文件()
* @param routeKey - key
*/
export function getViewComponent(routeKey: AuthRoute.RouteKey) {
return () => setViewComponentName(views[routeKey], routeKey) as Promise<Component>;
}
/** 给页面组件设置名称 */
async function setViewComponentName(asyncComponent: () => Promise<Component>, name: string) {
const component = (await asyncComponent()) as { default: Component };
Object.assign(component.default, { name });
return component;
}