-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(projects): format code style [调整代码格式]
- Loading branch information
1 parent
6a344ff
commit a9d58f8
Showing
7 changed files
with
176 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import type { RouteComponent } from 'vue-router'; | ||
import { BasicLayout, BlankLayout } from '@/layouts'; | ||
import { views } from '@/views'; | ||
import { isFunction } from '../common'; | ||
|
||
type Lazy<T> = () => Promise<T>; | ||
|
||
interface ModuleComponent { | ||
default: RouteComponent; | ||
} | ||
|
||
type LayoutComponent = Record<EnumType.LayoutComponentName, Lazy<ModuleComponent>>; | ||
|
||
/** | ||
* 获取布局的vue文件(懒加载的方式) | ||
* @param layoutType - 布局类型 | ||
*/ | ||
export function getLayoutComponent(layoutType: EnumType.LayoutComponentName) { | ||
const layoutComponent: LayoutComponent = { | ||
basic: BasicLayout, | ||
blank: BlankLayout | ||
}; | ||
return layoutComponent[layoutType]; | ||
} | ||
|
||
/** | ||
* 获取页面导入的vue文件 | ||
* @param routeKey - 路由key | ||
*/ | ||
export function getViewComponent(routeKey: AuthRoute.LastDegreeRouteKey) { | ||
if (!views[routeKey]) { | ||
throw new Error(`路由“${routeKey}”没有对应的组件文件!`); | ||
} | ||
return setViewComponentName(views[routeKey], routeKey); | ||
} | ||
|
||
/** 给页面组件设置名称 */ | ||
function setViewComponentName(component: RouteComponent | Lazy<ModuleComponent>, name: string) { | ||
if (isAsyncComponent(component)) { | ||
return async () => { | ||
const result = await component(); | ||
Object.assign(result.default, { name }); | ||
return result; | ||
}; | ||
} | ||
|
||
Object.assign(component, { name }); | ||
|
||
return component; | ||
} | ||
|
||
function isAsyncComponent(component: RouteComponent | Lazy<ModuleComponent>): component is Lazy<ModuleComponent> { | ||
return isFunction(component); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.