diff --git a/src/utils/router/component.ts b/src/utils/router/component.ts index a0ea6f84..e7bff664 100644 --- a/src/utils/router/component.ts +++ b/src/utils/router/component.ts @@ -1,32 +1,7 @@ import type { Component } from 'vue'; import { EnumLayoutComponentName } from '@/enum'; import { BasicLayout, BlankLayout } from '@/layouts'; -import { - Login, - NoPermission, - NotFound, - ServiceError, - DashboardAnalysis, - DashboardWorkbench, - DocumentVue, - DocumentVueNew, - DocumentVite, - DocumentNaive, - ComponentButton, - ComponentCard, - ComponentTable, - PluginMap, - PluginVideo, - PluginEditorQuill, - PluginEditorMarkdown, - PluginSwiper, - PluginCopy, - PluginIcon, - PluginPrint, - MultiMenuFirstSecond, - MultiMenuFirstSecondNewThird, - About -} from '@/views'; +import { views } from '@/views'; import type { LayoutComponentName } from '@/interface'; type LayoutComponent = Record Promise>; @@ -43,94 +18,12 @@ export function getLayoutComponent(layoutType: LayoutComponentName) { return () => setViewComponentName(layoutComponent[layoutType], EnumLayoutComponentName[layoutType]); } -/** 需要用到自身vue组件的页面 */ -type ViewComponentKey = Exclude< - AuthRoute.RouteKey, - | 'root' - | 'dashboard' - | 'document' - | 'document_project' - | 'component' - | 'plugin' - | 'plugin_editor' - | 'multi-menu' - | 'multi-menu_first' - | 'multi-menu_first_second-new' - | 'exception' ->; - -type ViewComponent = Record Promise>; - /** * 获取页面导入的vue文件(懒加载的方式) * @param routeKey - 路由key */ export function getViewComponent(routeKey: AuthRoute.RouteKey) { - const keys: ViewComponentKey[] = [ - 'login', - 'no-permission', - 'not-found', - 'service-error', - 'dashboard_analysis', - 'dashboard_workbench', - 'document_vue', - 'document_vue-new', - 'document_vite', - 'document_naive', - 'component_button', - 'component_card', - 'component_table', - 'plugin_map', - 'plugin_video', - 'plugin_editor_quill', - 'plugin_editor_markdown', - 'plugin_copy', - 'plugin_icon', - 'plugin_print', - 'plugin_swiper', - 'exception_403', - 'exception_404', - 'exception_500', - 'multi-menu_first_second', - 'multi-menu_first_second-new_third', - 'about', - 'not-found-page' - ]; - - const key = keys.includes(routeKey as ViewComponentKey) ? (routeKey as ViewComponentKey) : 'not-found'; - - const viewComponent: ViewComponent = { - login: Login, - 'no-permission': NoPermission, - 'not-found': NotFound, - 'service-error': ServiceError, - dashboard_analysis: DashboardAnalysis, - dashboard_workbench: DashboardWorkbench, - document_vue: DocumentVue, - 'document_vue-new': DocumentVueNew, - document_vite: DocumentVite, - document_naive: DocumentNaive, - component_button: ComponentButton, - component_card: ComponentCard, - component_table: ComponentTable, - plugin_map: PluginMap, - plugin_video: PluginVideo, - plugin_editor_quill: PluginEditorQuill, - plugin_editor_markdown: PluginEditorMarkdown, - plugin_copy: PluginCopy, - plugin_icon: PluginIcon, - plugin_print: PluginPrint, - plugin_swiper: PluginSwiper, - exception_403: NoPermission, - exception_404: NotFound, - exception_500: ServiceError, - 'multi-menu_first_second': MultiMenuFirstSecond, - 'multi-menu_first_second-new_third': MultiMenuFirstSecondNewThird, - about: About, - 'not-found-page': NotFound - }; - - return () => setViewComponentName(viewComponent[key], key) as Promise; + return () => setViewComponentName(views[routeKey], routeKey) as Promise; } /** 给页面组件设置名称 */ diff --git a/src/views/about/index.ts b/src/views/about/index.ts deleted file mode 100644 index 81fd049b..00000000 --- a/src/views/about/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -const About = () => import('./index.vue'); - -export { About }; diff --git a/src/views/component/index.ts b/src/views/component/index.ts deleted file mode 100644 index c5a65a55..00000000 --- a/src/views/component/index.ts +++ /dev/null @@ -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 }; diff --git a/src/views/dashboard/index.ts b/src/views/dashboard/index.ts deleted file mode 100644 index 06e6c247..00000000 --- a/src/views/dashboard/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -const DashboardAnalysis = () => import('./analysis/index.vue'); -const DashboardWorkbench = () => import('./workbench/index.vue'); - -export { DashboardAnalysis, DashboardWorkbench }; diff --git a/src/views/document/index.ts b/src/views/document/index.ts deleted file mode 100644 index 43f1f0b2..00000000 --- a/src/views/document/index.ts +++ /dev/null @@ -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 }; diff --git a/src/views/exception/403/index.vue b/src/views/exception/403/index.vue new file mode 100644 index 00000000..55544a9f --- /dev/null +++ b/src/views/exception/403/index.vue @@ -0,0 +1,8 @@ + + + + diff --git a/src/views/exception/404/index.vue b/src/views/exception/404/index.vue new file mode 100644 index 00000000..755e9b84 --- /dev/null +++ b/src/views/exception/404/index.vue @@ -0,0 +1,8 @@ + + + + diff --git a/src/views/exception/500/index.vue b/src/views/exception/500/index.vue new file mode 100644 index 00000000..50464de4 --- /dev/null +++ b/src/views/exception/500/index.vue @@ -0,0 +1,8 @@ + + + + diff --git a/src/views/index.ts b/src/views/index.ts index 24d3ff3b..f0dbb75c 100644 --- a/src/views/index.ts +++ b/src/views/index.ts @@ -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 Promise>; + +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(); diff --git a/src/views/multi-menu/index.ts b/src/views/multi-menu/index.ts deleted file mode 100644 index fe00cb62..00000000 --- a/src/views/multi-menu/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -const MultiMenuFirstSecond = () => import('./first/second/index.vue'); -const MultiMenuFirstSecondNewThird = () => import('./first/second-new/third/index.vue'); - -export { MultiMenuFirstSecond, MultiMenuFirstSecondNewThird }; diff --git a/src/views/plugin/index.ts b/src/views/plugin/index.ts deleted file mode 100644 index 219e2ef3..00000000 --- a/src/views/plugin/index.ts +++ /dev/null @@ -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 -}; diff --git a/src/views/system/exception/components/ExceptionBase.vue b/src/views/system-view/components/ExceptionBase.vue similarity index 100% rename from src/views/system/exception/components/ExceptionBase.vue rename to src/views/system-view/components/ExceptionBase.vue diff --git a/src/views/system/exception/components/index.ts b/src/views/system-view/components/index.ts similarity index 100% rename from src/views/system/exception/components/index.ts rename to src/views/system-view/components/index.ts diff --git a/src/views/system/login/components/BindWechat/index.vue b/src/views/system-view/login/components/BindWechat/index.vue similarity index 100% rename from src/views/system/login/components/BindWechat/index.vue rename to src/views/system-view/login/components/BindWechat/index.vue diff --git a/src/views/system/login/components/CodeLogin/index.vue b/src/views/system-view/login/components/CodeLogin/index.vue similarity index 100% rename from src/views/system/login/components/CodeLogin/index.vue rename to src/views/system-view/login/components/CodeLogin/index.vue diff --git a/src/views/system/login/components/LoginBg/components/CornerBottom.vue b/src/views/system-view/login/components/LoginBg/components/CornerBottom.vue similarity index 100% rename from src/views/system/login/components/LoginBg/components/CornerBottom.vue rename to src/views/system-view/login/components/LoginBg/components/CornerBottom.vue diff --git a/src/views/system/login/components/LoginBg/components/CornerTop.vue b/src/views/system-view/login/components/LoginBg/components/CornerTop.vue similarity index 100% rename from src/views/system/login/components/LoginBg/components/CornerTop.vue rename to src/views/system-view/login/components/LoginBg/components/CornerTop.vue diff --git a/src/views/system/login/components/LoginBg/components/index.ts b/src/views/system-view/login/components/LoginBg/components/index.ts similarity index 100% rename from src/views/system/login/components/LoginBg/components/index.ts rename to src/views/system-view/login/components/LoginBg/components/index.ts diff --git a/src/views/system/login/components/LoginBg/index.vue b/src/views/system-view/login/components/LoginBg/index.vue similarity index 100% rename from src/views/system/login/components/LoginBg/index.vue rename to src/views/system-view/login/components/LoginBg/index.vue diff --git a/src/views/system/login/components/PwdLogin/components/OtherLogin.vue b/src/views/system-view/login/components/PwdLogin/components/OtherLogin.vue similarity index 100% rename from src/views/system/login/components/PwdLogin/components/OtherLogin.vue rename to src/views/system-view/login/components/PwdLogin/components/OtherLogin.vue diff --git a/src/views/system/login/components/PwdLogin/components/index.ts b/src/views/system-view/login/components/PwdLogin/components/index.ts similarity index 100% rename from src/views/system/login/components/PwdLogin/components/index.ts rename to src/views/system-view/login/components/PwdLogin/components/index.ts diff --git a/src/views/system/login/components/PwdLogin/index.vue b/src/views/system-view/login/components/PwdLogin/index.vue similarity index 100% rename from src/views/system/login/components/PwdLogin/index.vue rename to src/views/system-view/login/components/PwdLogin/index.vue diff --git a/src/views/system/login/components/Register/index.vue b/src/views/system-view/login/components/Register/index.vue similarity index 100% rename from src/views/system/login/components/Register/index.vue rename to src/views/system-view/login/components/Register/index.vue diff --git a/src/views/system/login/components/ResetPwd/index.vue b/src/views/system-view/login/components/ResetPwd/index.vue similarity index 100% rename from src/views/system/login/components/ResetPwd/index.vue rename to src/views/system-view/login/components/ResetPwd/index.vue diff --git a/src/views/system/login/components/index.ts b/src/views/system-view/login/components/index.ts similarity index 100% rename from src/views/system/login/components/index.ts rename to src/views/system-view/login/components/index.ts diff --git a/src/views/system/login/index.vue b/src/views/system-view/login/index.vue similarity index 100% rename from src/views/system/login/index.vue rename to src/views/system-view/login/index.vue diff --git a/src/views/system/exception/no-permission/index.vue b/src/views/system-view/no-permission/index.vue similarity index 100% rename from src/views/system/exception/no-permission/index.vue rename to src/views/system-view/no-permission/index.vue diff --git a/src/views/system/exception/not-found/index.vue b/src/views/system-view/not-found-page/index.vue similarity index 100% rename from src/views/system/exception/not-found/index.vue rename to src/views/system-view/not-found-page/index.vue diff --git a/src/views/system-view/not-found/index.vue b/src/views/system-view/not-found/index.vue new file mode 100644 index 00000000..65110f04 --- /dev/null +++ b/src/views/system-view/not-found/index.vue @@ -0,0 +1,8 @@ + + + + diff --git a/src/views/system/exception/service-error/index.vue b/src/views/system-view/service-error/index.vue similarity index 100% rename from src/views/system/exception/service-error/index.vue rename to src/views/system-view/service-error/index.vue diff --git a/src/views/system/index.ts b/src/views/system/index.ts deleted file mode 100644 index 32aa8ffb..00000000 --- a/src/views/system/index.ts +++ /dev/null @@ -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 };