refactor(projects): 重构路由页面组件的导入

This commit is contained in:
Soybean
2022-02-11 16:14:30 +08:00
parent a7a269d6a6
commit e65034d946
31 changed files with 65 additions and 163 deletions

View File

@ -1,3 +0,0 @@
const About = () => import('./index.vue');
export { About };

View File

@ -1,5 +0,0 @@
const ComponentButton = () => import('./button/index.vue');
const ComponentCard = () => import('./card/index.vue');
const ComponentTable = () => import('./table/index.vue');
export { ComponentButton, ComponentCard, ComponentTable };

View File

@ -1,4 +0,0 @@
const DashboardAnalysis = () => import('./analysis/index.vue');
const DashboardWorkbench = () => import('./workbench/index.vue');
export { DashboardAnalysis, DashboardWorkbench };

View File

@ -1,6 +0,0 @@
const DocumentVue = () => import('./vue/index.vue');
const DocumentVueNew = () => import('./vue-new/index.vue');
const DocumentVite = () => import('./vite/index.vue');
const DocumentNaive = () => import('./naive/index.vue');
export { DocumentVue, DocumentVueNew, DocumentVite, DocumentNaive };

View File

@ -0,0 +1,8 @@
<template>
<exception-base type="403" />
</template>
<script lang="ts" setup>
import { ExceptionBase } from '../../system-view/components';
</script>
<style scoped></style>

View File

@ -0,0 +1,8 @@
<template>
<exception-base type="404" />
</template>
<script lang="ts" setup>
import { ExceptionBase } from '../../system-view/components';
</script>
<style scoped></style>

View File

@ -0,0 +1,8 @@
<template>
<exception-base type="500" />
</template>
<script lang="ts" setup>
import { ExceptionBase } from '../../system-view/components';
</script>
<style scoped></style>

View File

@ -1,7 +1,31 @@
export * from './system';
export * from './dashboard';
export * from './document';
export * from './component';
export * from './plugin';
export * from './multi-menu';
export * from './about';
import type { Component } from 'vue';
type ViewComponent = Record<string, () => Promise<Component>>;
const importViews = import.meta.glob('./**/index.vue');
const COMPONENTS_KEY = 'components';
const PREFIX = './';
const SUFFIX = '/index.vue';
const PATH_SPLIT_MARK = '/';
const ROUTE_KEY_SPLIT_MARK = '_';
/** 系统的内置路由该文件夹名称不作为RouteKey */
const SYSTEM_VIEW = 'system-view_';
/** 过滤掉组件文件 */
const viewKeys = Object.keys(importViews).filter(key => !key.includes(COMPONENTS_KEY));
function getViewComponent() {
const components: ViewComponent = {};
viewKeys.forEach(key => {
const routeKey = key
.replace(PREFIX, '')
.replace(SUFFIX, '')
.replaceAll(PATH_SPLIT_MARK, ROUTE_KEY_SPLIT_MARK)
.replace(SYSTEM_VIEW, '');
components[routeKey] = importViews[key];
});
return components;
}
export const views = getViewComponent();

View File

@ -1,4 +0,0 @@
const MultiMenuFirstSecond = () => import('./first/second/index.vue');
const MultiMenuFirstSecondNewThird = () => import('./first/second-new/third/index.vue');
export { MultiMenuFirstSecond, MultiMenuFirstSecondNewThird };

View File

@ -1,19 +0,0 @@
const PluginMap = () => import('./map/index.vue');
const PluginVideo = () => import('./video/index.vue');
const PluginEditorQuill = () => import('./editor/quill/index.vue');
const PluginEditorMarkdown = () => import('./editor/markdown/index.vue');
const PluginSwiper = () => import('./swiper/index.vue');
const PluginCopy = () => import('./copy/index.vue');
const PluginIcon = () => import('./icon/index.vue');
const PluginPrint = () => import('./print/index.vue');
export {
PluginMap,
PluginVideo,
PluginEditorQuill,
PluginEditorMarkdown,
PluginSwiper,
PluginCopy,
PluginIcon,
PluginPrint
};

View File

@ -0,0 +1,8 @@
<template>
<exception-base type="404" />
</template>
<script lang="ts" setup>
import { ExceptionBase } from '../components';
</script>
<style scoped></style>

View File

@ -1,6 +0,0 @@
const Login = () => import('./login/index.vue');
const NoPermission = () => import('./exception/no-permission/index.vue');
const NotFound = () => import('./exception/not-found/index.vue');
const ServiceError = () => import('./exception/service-error/index.vue');
export { Login, NoPermission, NotFound, ServiceError };