2022-01-03 22:20:10 +08:00
|
|
|
import type { Component } from 'vue';
|
2022-01-21 23:59:14 +08:00
|
|
|
import { EnumLayoutComponentName } from '@/enum';
|
|
|
|
|
import { BasicLayout, BlankLayout } from '@/layouts';
|
2022-02-11 16:14:30 +08:00
|
|
|
import { views } from '@/views';
|
2022-01-21 23:59:14 +08:00
|
|
|
|
2022-03-12 17:45:37 +08:00
|
|
|
type LayoutComponent = Record<EnumType.LayoutComponentName, () => Promise<Component>>;
|
2022-01-21 23:59:14 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取页面导入的vue文件(懒加载的方式)
|
|
|
|
|
* @param layoutType - 布局类型
|
|
|
|
|
*/
|
2022-03-12 17:45:37 +08:00
|
|
|
export function getLayoutComponent(layoutType: EnumType.LayoutComponentName) {
|
2022-01-21 23:59:14 +08:00
|
|
|
const layoutComponent: LayoutComponent = {
|
|
|
|
|
basic: BasicLayout,
|
2022-03-12 16:21:40 +08:00
|
|
|
blank: BlankLayout,
|
2022-01-21 23:59:14 +08:00
|
|
|
};
|
|
|
|
|
return () => setViewComponentName(layoutComponent[layoutType], EnumLayoutComponentName[layoutType]);
|
|
|
|
|
}
|
2022-01-03 22:20:10 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取页面导入的vue文件(懒加载的方式)
|
2022-01-21 23:59:14 +08:00
|
|
|
* @param routeKey - 路由key
|
2022-01-03 22:20:10 +08:00
|
|
|
*/
|
|
|
|
|
export function getViewComponent(routeKey: AuthRoute.RouteKey) {
|
2022-02-11 16:14:30 +08:00
|
|
|
return () => setViewComponentName(views[routeKey], routeKey) as Promise<Component>;
|
2022-01-03 22:20:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 给页面组件设置名称 */
|
|
|
|
|
async function setViewComponentName(asyncComponent: () => Promise<Component>, name: string) {
|
|
|
|
|
const component = (await asyncComponent()) as { default: Component };
|
|
|
|
|
Object.assign(component.default, { name });
|
|
|
|
|
return component;
|
|
|
|
|
}
|