@skyroc/scripts 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +508 -0
- package/dist/cli.mjs +78 -0
- package/dist/config-BKkdncJS.mjs +987 -0
- package/dist/index.mjs +14 -0
- package/package.json +83 -0
- package/templates/admin/.env +62 -0
- package/templates/admin/.env.prod +7 -0
- package/templates/admin/.env.test +7 -0
- package/templates/admin/.oxlintrc.json +6 -0
- package/templates/admin/README.md +508 -0
- package/templates/admin/index.html +14 -0
- package/templates/admin/package.json +105 -0
- package/templates/admin/public/favicon.svg +3 -0
- package/templates/admin/src/App.tsx +71 -0
- package/templates/admin/src/assets/audio/wechat-style-notification.wav +0 -0
- package/templates/admin/src/assets/imgs/skyroc.jpg +0 -0
- package/templates/admin/src/assets/svg-icon/activity.svg +1 -0
- package/templates/admin/src/assets/svg-icon/at-sign.svg +1 -0
- package/templates/admin/src/assets/svg-icon/avatar.svg +1 -0
- package/templates/admin/src/assets/svg-icon/banner.svg +1 -0
- package/templates/admin/src/assets/svg-icon/cast.svg +1 -0
- package/templates/admin/src/assets/svg-icon/chrome.svg +1 -0
- package/templates/admin/src/assets/svg-icon/copy.svg +1 -0
- package/templates/admin/src/assets/svg-icon/custom-icon.svg +1 -0
- package/templates/admin/src/assets/svg-icon/empty-data.svg +1 -0
- package/templates/admin/src/assets/svg-icon/error.svg +1 -0
- package/templates/admin/src/assets/svg-icon/expectation.svg +1 -0
- package/templates/admin/src/assets/svg-icon/heart.svg +1 -0
- package/templates/admin/src/assets/svg-icon/logo.svg +15 -0
- package/templates/admin/src/assets/svg-icon/network-error.svg +1 -0
- package/templates/admin/src/assets/svg-icon/no-icon.svg +1 -0
- package/templates/admin/src/assets/svg-icon/no-permission.svg +1 -0
- package/templates/admin/src/assets/svg-icon/not-found.svg +1 -0
- package/templates/admin/src/assets/svg-icon/service-error.svg +1 -0
- package/templates/admin/src/bootstrap.tsx +60 -0
- package/templates/admin/src/components/SkyrocAvatar.tsx +13 -0
- package/templates/admin/src/components/SystemLogo.tsx +7 -0
- package/templates/admin/src/config.ts +125 -0
- package/templates/admin/src/features/antd/AntdProvider.tsx +21 -0
- package/templates/admin/src/features/auth/components/UserAvatar.tsx +76 -0
- package/templates/admin/src/features/auth/use-auth-form-rules.ts +83 -0
- package/templates/admin/src/features/auth/use-auth.ts +96 -0
- package/templates/admin/src/features/auth/use-login.ts +72 -0
- package/templates/admin/src/features/effects/GlobalEffect.tsx +15 -0
- package/templates/admin/src/features/menus/dynamic-routes.ts +10 -0
- package/templates/admin/src/features/menus/extras.ts +3 -0
- package/templates/admin/src/features/menus/menu-category.ts +14 -0
- package/templates/admin/src/features/menus/menu-config.ts +5 -0
- package/templates/admin/src/features/router/RouterProvider.tsx +18 -0
- package/templates/admin/src/features/router/guard.ts +97 -0
- package/templates/admin/src/features/router/index.ts +52 -0
- package/templates/admin/src/features/router/routeTree.gen.ts +237 -0
- package/templates/admin/src/features/router/router-ref.ts +24 -0
- package/templates/admin/src/locales/antd.ts +8 -0
- package/templates/admin/src/locales/index.ts +22 -0
- package/templates/admin/src/locales/sync.ts +14 -0
- package/templates/admin/src/main.tsx +9 -0
- package/templates/admin/src/pages/(admin)/home/index.tsx +46 -0
- package/templates/admin/src/pages/(admin)/layout.tsx +44 -0
- package/templates/admin/src/pages/(auth)/login/index.tsx +102 -0
- package/templates/admin/src/pages/(auth)/login/layout.tsx +71 -0
- package/templates/admin/src/pages/(auth)/login-out.tsx +27 -0
- package/templates/admin/src/pages/(errors)/403.tsx +16 -0
- package/templates/admin/src/pages/(errors)/404.tsx +16 -0
- package/templates/admin/src/pages/(errors)/500.tsx +16 -0
- package/templates/admin/src/pages/__root.tsx +54 -0
- package/templates/admin/src/pages/error.tsx +19 -0
- package/templates/admin/src/pages/index.tsx +14 -0
- package/templates/admin/src/pages/loading.tsx +45 -0
- package/templates/admin/src/pages/not-found.tsx +9 -0
- package/templates/admin/src/plugins/app.tsx +47 -0
- package/templates/admin/src/plugins/assets.ts +4 -0
- package/templates/admin/src/plugins/index.ts +32 -0
- package/templates/admin/src/service/adapter.ts +63 -0
- package/templates/admin/src/service/api/auth/api.ts +31 -0
- package/templates/admin/src/service/api/auth/hooks.ts +28 -0
- package/templates/admin/src/service/api/auth/index.ts +10 -0
- package/templates/admin/src/service/api/auth/keys.ts +7 -0
- package/templates/admin/src/service/api/auth/urls.ts +7 -0
- package/templates/admin/src/service/api/index.ts +2 -0
- package/templates/admin/src/service/api/route/api.ts +7 -0
- package/templates/admin/src/service/api/route/hooks.ts +21 -0
- package/templates/admin/src/service/api/route/index.ts +10 -0
- package/templates/admin/src/service/api/route/keys.ts +3 -0
- package/templates/admin/src/service/api/route/urls.ts +5 -0
- package/templates/admin/src/service/queryClient.ts +13 -0
- package/templates/admin/src/service/request/index.ts +62 -0
- package/templates/admin/src/styles/scss/global.scss +1 -0
- package/templates/admin/src/styles/scss/scrollbar.scss +28 -0
- package/templates/admin/src/types/auto-imports.d.ts +186 -0
- package/templates/admin/src/types/global.d.ts +16 -0
- package/templates/admin/src/types/router.d.ts +14 -0
- package/templates/admin/src/types/storage.d.ts +17 -0
- package/templates/admin/src/types/vite-env.d.ts +117 -0
- package/templates/admin/src/utils/common.tsx +38 -0
- package/templates/admin/src/utils/icon.ts +9 -0
- package/templates/admin/src/utils/service.ts +75 -0
- package/templates/admin/src/utils/storage.ts +7 -0
- package/templates/admin/tsconfig.json +22 -0
- package/templates/admin/uno.config.ts +18 -0
- package/templates/admin/vite.config.ts +13 -0
- package/templates/admin-shell/i18n/atoms/lang.ts +20 -0
- package/templates/admin-shell/i18n/config/default.ts +11 -0
- package/templates/admin-shell/i18n/features/lang/LangEffect.tsx +25 -0
- package/templates/admin-shell/i18n/features/lang/LangSwitch.tsx +49 -0
- package/templates/admin-shell/i18n/hooks/use-lang.ts +47 -0
- package/templates/admin-shell/i18n/i18n.ts +116 -0
- package/templates/admin-shell/i18n/index.ts +23 -0
- package/templates/admin-shell/i18n/langs/en-us/common.json +49 -0
- package/templates/admin-shell/i18n/langs/en-us/datatable.json +8 -0
- package/templates/admin-shell/i18n/langs/en-us/dropdown.json +9 -0
- package/templates/admin-shell/i18n/langs/en-us/form.json +27 -0
- package/templates/admin-shell/i18n/langs/en-us/icon.json +13 -0
- package/templates/admin-shell/i18n/langs/en-us/notification.json +20 -0
- package/templates/admin-shell/i18n/langs/en-us/page.json +442 -0
- package/templates/admin-shell/i18n/langs/en-us/request.json +8 -0
- package/templates/admin-shell/i18n/langs/en-us/route.json +84 -0
- package/templates/admin-shell/i18n/langs/en-us/system.json +9 -0
- package/templates/admin-shell/i18n/langs/en-us/theme.json +173 -0
- package/templates/admin-shell/i18n/langs/index.ts +63 -0
- package/templates/admin-shell/i18n/langs/zh-cn/common.json +49 -0
- package/templates/admin-shell/i18n/langs/zh-cn/datatable.json +8 -0
- package/templates/admin-shell/i18n/langs/zh-cn/dropdown.json +9 -0
- package/templates/admin-shell/i18n/langs/zh-cn/form.json +27 -0
- package/templates/admin-shell/i18n/langs/zh-cn/icon.json +13 -0
- package/templates/admin-shell/i18n/langs/zh-cn/notification.json +20 -0
- package/templates/admin-shell/i18n/langs/zh-cn/page.json +442 -0
- package/templates/admin-shell/i18n/langs/zh-cn/request.json +8 -0
- package/templates/admin-shell/i18n/langs/zh-cn/route.json +84 -0
- package/templates/admin-shell/i18n/langs/zh-cn/system.json +9 -0
- package/templates/admin-shell/i18n/langs/zh-cn/theme.json +173 -0
- package/templates/admin-shell/i18n/types/i18n.ts +29 -0
- package/templates/admin-shell/i18n/types.ts +53 -0
- package/templates/admin-shell/i18n/utils/helpers.ts +18 -0
- package/templates/admin-shell/layouts/AdminLayout.tsx +161 -0
- package/templates/admin-shell/layouts/constant.ts +56 -0
- package/templates/admin-shell/layouts/context.tsx +101 -0
- package/templates/admin-shell/layouts/features/menus/MenuBadge.tsx +76 -0
- package/templates/admin-shell/layouts/features/menus/dynamic-routes.ts +146 -0
- package/templates/admin-shell/layouts/features/menus/menu-generator.tsx +444 -0
- package/templates/admin-shell/layouts/features/menus/menu-renderer.tsx +149 -0
- package/templates/admin-shell/layouts/features/menus/permissions.ts +28 -0
- package/templates/admin-shell/layouts/features/menus/use-menus.ts +98 -0
- package/templates/admin-shell/layouts/features/use-route.ts +30 -0
- package/templates/admin-shell/layouts/index.ts +44 -0
- package/templates/admin-shell/layouts/materials/index.ts +6 -0
- package/templates/admin-shell/layouts/materials/libs/admin-layout/index.module.css +63 -0
- package/templates/admin-shell/layouts/materials/libs/admin-layout/index.module.css.d.ts +18 -0
- package/templates/admin-shell/layouts/materials/libs/admin-layout/index.tsx +238 -0
- package/templates/admin-shell/layouts/materials/libs/admin-layout/shared.ts +67 -0
- package/templates/admin-shell/layouts/materials/libs/page-tab/ButtonTab.tsx +44 -0
- package/templates/admin-shell/layouts/materials/libs/page-tab/ChromeTab.tsx +54 -0
- package/templates/admin-shell/layouts/materials/libs/page-tab/ChromeTabBg.tsx +30 -0
- package/templates/admin-shell/layouts/materials/libs/page-tab/SliderTab.tsx +44 -0
- package/templates/admin-shell/layouts/materials/libs/page-tab/SvgClose.tsx +51 -0
- package/templates/admin-shell/layouts/materials/libs/page-tab/hook.ts +34 -0
- package/templates/admin-shell/layouts/materials/libs/page-tab/index.module.css +120 -0
- package/templates/admin-shell/layouts/materials/libs/page-tab/index.module.css.d.ts +18 -0
- package/templates/admin-shell/layouts/materials/libs/page-tab/index.tsx +76 -0
- package/templates/admin-shell/layouts/materials/libs/page-tab/shared.ts +32 -0
- package/templates/admin-shell/layouts/materials/types/index.ts +322 -0
- package/templates/admin-shell/layouts/modules/AdminContent.tsx +285 -0
- package/templates/admin-shell/layouts/modules/AdminFooter.tsx +13 -0
- package/templates/admin-shell/layouts/modules/AdminLogo.tsx +28 -0
- package/templates/admin-shell/layouts/modules/AdminSider.tsx +50 -0
- package/templates/admin-shell/layouts/modules/admin-header/AdminHeader.tsx +132 -0
- package/templates/admin-shell/layouts/modules/admin-header/components/Breadcrumb.tsx +62 -0
- package/templates/admin-shell/layouts/modules/admin-header/components/ThemeButton.tsx +24 -0
- package/templates/admin-shell/layouts/modules/admin-menu/AdminMenu.tsx +37 -0
- package/templates/admin-shell/layouts/modules/admin-menu/components/FirstLevelMenu.tsx +156 -0
- package/templates/admin-shell/layouts/modules/admin-menu/components/HorizontalMenu.tsx +88 -0
- package/templates/admin-shell/layouts/modules/admin-menu/components/MenuPortal.tsx +28 -0
- package/templates/admin-shell/layouts/modules/admin-menu/components/VerticalMenu.tsx +123 -0
- package/templates/admin-shell/layouts/modules/admin-menu/enum.ts +47 -0
- package/templates/admin-shell/layouts/modules/admin-menu/modules/Horizontal.tsx +22 -0
- package/templates/admin-shell/layouts/modules/admin-menu/modules/TopHybridHeaderFirst.tsx +15 -0
- package/templates/admin-shell/layouts/modules/admin-menu/modules/TopHybridSidebarFirst.tsx +18 -0
- package/templates/admin-shell/layouts/modules/admin-menu/modules/Vertical.tsx +14 -0
- package/templates/admin-shell/layouts/modules/admin-menu/modules/VerticalHybridHeaderFirst.tsx +18 -0
- package/templates/admin-shell/layouts/modules/admin-menu/modules/VerticalMix.tsx +132 -0
- package/templates/admin-shell/layouts/modules/admin-search/AdminSearch.tsx +36 -0
- package/templates/admin-shell/layouts/modules/admin-search/components/SearchFooter.tsx +38 -0
- package/templates/admin-shell/layouts/modules/admin-search/components/SearchModal.tsx +171 -0
- package/templates/admin-shell/layouts/modules/admin-search/components/SearchResult.tsx +43 -0
- package/templates/admin-shell/layouts/modules/admin-tab/AdminTab.tsx +125 -0
- package/templates/admin-shell/layouts/modules/admin-tab/components/TabContextMenu.tsx +107 -0
- package/templates/admin-shell/layouts/modules/admin-tab/hooks/useTabScroll.ts +86 -0
- package/templates/admin-shell/layouts/modules/shared/logo.ts +42 -0
- package/templates/admin-shell/layouts/modules/theme-drawer/ThemeDrawer.tsx +68 -0
- package/templates/admin-shell/layouts/modules/theme-drawer/components/AnimatedCollapse.tsx +36 -0
- package/templates/admin-shell/layouts/modules/theme-drawer/components/AnimatedItem.tsx +35 -0
- package/templates/admin-shell/layouts/modules/theme-drawer/components/LayoutModeCard.tsx +110 -0
- package/templates/admin-shell/layouts/modules/theme-drawer/components/SettingItem.tsx +31 -0
- package/templates/admin-shell/layouts/modules/theme-drawer/modules/ConfigOperation.tsx +53 -0
- package/templates/admin-shell/layouts/modules/theme-drawer/modules/appearance/CustomPicker.tsx +105 -0
- package/templates/admin-shell/layouts/modules/theme-drawer/modules/appearance/ThemeColor.tsx +58 -0
- package/templates/admin-shell/layouts/modules/theme-drawer/modules/appearance/ThemeSchema.tsx +42 -0
- package/templates/admin-shell/layouts/modules/theme-drawer/modules/appearance/ThemeToken.tsx +44 -0
- package/templates/admin-shell/layouts/modules/theme-drawer/modules/appearance/index.tsx +23 -0
- package/templates/admin-shell/layouts/modules/theme-drawer/modules/general/GlobalSettings.tsx +57 -0
- package/templates/admin-shell/layouts/modules/theme-drawer/modules/general/ThemeGeneral.tsx +20 -0
- package/templates/admin-shell/layouts/modules/theme-drawer/modules/general/WatermarkSettings.tsx +103 -0
- package/templates/admin-shell/layouts/modules/theme-drawer/modules/layout/ContentSettings.tsx +100 -0
- package/templates/admin-shell/layouts/modules/theme-drawer/modules/layout/FooterSettings.tsx +71 -0
- package/templates/admin-shell/layouts/modules/theme-drawer/modules/layout/HeaderSettings.tsx +63 -0
- package/templates/admin-shell/layouts/modules/theme-drawer/modules/layout/LayoutMode.tsx +73 -0
- package/templates/admin-shell/layouts/modules/theme-drawer/modules/layout/SiderSettings.tsx +124 -0
- package/templates/admin-shell/layouts/modules/theme-drawer/modules/layout/TabSettings.tsx +95 -0
- package/templates/admin-shell/layouts/modules/theme-drawer/modules/layout/ThemeLayout.tsx +32 -0
- package/templates/admin-shell/layouts/modules/theme-drawer/modules/preset/ThemePreset.tsx +132 -0
- package/templates/admin-shell/layouts/options.tsx +79 -0
- package/templates/admin-shell/layouts/setup.ts +102 -0
- package/templates/admin-shell/layouts/state/AdminEffect.tsx +56 -0
- package/templates/admin-shell/layouts/state/AdminTabEffect.tsx +28 -0
- package/templates/admin-shell/layouts/state/index.ts +3 -0
- package/templates/admin-shell/layouts/state/menus/MenuToggler.tsx +53 -0
- package/templates/admin-shell/layouts/state/menus/use-admin-menu-badges.ts +46 -0
- package/templates/admin-shell/layouts/state/menus/use-admin-menus.tsx +164 -0
- package/templates/admin-shell/layouts/state/tabs/index.ts +1 -0
- package/templates/admin-shell/layouts/state/tabs/shared.tsx +148 -0
- package/templates/admin-shell/layouts/state/tabs/use-admin-tab.ts +377 -0
- package/templates/admin-shell/layouts/state/use-admin-state.ts +118 -0
- package/templates/admin-shell/layouts/types/router.d.ts +10 -0
- package/templates/admin-shell/layouts/types/storage.ts +18 -0
- package/templates/admin-shell/notification/NotificationButton.tsx +91 -0
- package/templates/admin-shell/notification/NotificationContext.ts +8 -0
- package/templates/admin-shell/notification/NotificationPanel.tsx +194 -0
- package/templates/admin-shell/notification/NotificationProvider.tsx +59 -0
- package/templates/admin-shell/notification/index.ts +12 -0
- package/templates/admin-shell/notification/mock.ts +59 -0
- package/templates/admin-shell/notification/notification-store.ts +438 -0
- package/templates/admin-shell/notification/notification.css +60 -0
- package/templates/admin-shell/notification/types.ts +104 -0
- package/templates/admin-shell/notification/use-notification.ts +51 -0
- package/templates/admin-shell/notification/useNotificationContext.ts +14 -0
- package/templates/admin-shell/runtime/app-update.ts +156 -0
- package/templates/admin-shell/runtime/dayjs.ts +20 -0
- package/templates/admin-shell/runtime/iconify.ts +17 -0
- package/templates/admin-shell/runtime/index.ts +10 -0
- package/templates/admin-shell/runtime/nprogress.ts +25 -0
- package/templates/admin-shell/runtime/plugins.ts +62 -0
- package/templates/admin-shell/styles/global.css +54 -0
- package/templates/admin-shell/styles/nprogress.css +85 -0
- package/templates/admin-shell/styles/reset.css +378 -0
- package/templates/admin-shell/theme/antd/AntdProvider.tsx +106 -0
- package/templates/admin-shell/theme/antd/index.ts +23 -0
- package/templates/admin-shell/theme/antd/shared.ts +80 -0
- package/templates/admin-shell/theme/antd/ui.ts +250 -0
- package/templates/admin-shell/theme/antd-algorithm/algorithm/dark/colors.ts +99 -0
- package/templates/admin-shell/theme/antd-algorithm/algorithm/dark/index.ts +87 -0
- package/templates/admin-shell/theme/antd-algorithm/algorithm/default/colors.ts +91 -0
- package/templates/admin-shell/theme/antd-algorithm/algorithm/default/index.ts +77 -0
- package/templates/admin-shell/theme/antd-algorithm/index.ts +80 -0
- package/templates/admin-shell/theme/antd-algorithm/seed/index.ts +41 -0
- package/templates/admin-shell/theme/antd-algorithm/shared/colorAlgorithm.ts +10 -0
- package/templates/admin-shell/theme/antd-algorithm/shared/genColorMapToken.ts +165 -0
- package/templates/admin-shell/theme/antd-algorithm/shared/genCommonMapToken.ts +23 -0
- package/templates/admin-shell/theme/antd-algorithm/shared/genControlHeight.ts +14 -0
- package/templates/admin-shell/theme/antd-algorithm/shared/genFontMapToken.ts +274 -0
- package/templates/admin-shell/theme/antd-algorithm/shared/genRadiusMapToken.ts +139 -0
- package/templates/admin-shell/theme/antd-algorithm/shared/genSizeMapToken.ts +114 -0
- package/templates/admin-shell/theme/antd-algorithm/types/index.ts +20 -0
- package/templates/admin-shell/theme/components/ThemeEffect.tsx +55 -0
- package/templates/admin-shell/theme/components/ThemeSchemaSegmented.tsx +27 -0
- package/templates/admin-shell/theme/components/ThemeSchemaSwitch.tsx +77 -0
- package/templates/admin-shell/theme/components/shared.ts +5 -0
- package/templates/admin-shell/theme/config/default.ts +108 -0
- package/templates/admin-shell/theme/config/index.ts +1 -0
- package/templates/admin-shell/theme/hooks/index.ts +2 -0
- package/templates/admin-shell/theme/hooks/use-theme.ts +244 -0
- package/templates/admin-shell/theme/index.ts +78 -0
- package/templates/admin-shell/theme/presets/azir.json +39 -0
- package/templates/admin-shell/theme/presets/compact.json +38 -0
- package/templates/admin-shell/theme/presets/dark.json +93 -0
- package/templates/admin-shell/theme/presets/default.json +95 -0
- package/templates/admin-shell/theme/presets/index.ts +29 -0
- package/templates/admin-shell/theme/presets/shadcn.json +99 -0
- package/templates/admin-shell/theme/setup.ts +115 -0
- package/templates/admin-shell/theme/types/index.ts +27 -0
- package/templates/admin-shell/theme/types/theme.d.ts +316 -0
- package/templates/admin-shell/theme/utils/dark-mode.ts +46 -0
- package/templates/admin-shell/theme/utils/filters.ts +20 -0
- package/templates/admin-shell/theme/utils/index.ts +3 -0
- package/templates/admin-shell/theme/utils/settings.ts +43 -0
- package/templates/admin-shell/types/api/auth.d.ts +148 -0
- package/templates/admin-shell/types/api/common.d.ts +54 -0
- package/templates/admin-shell/types/api/route.d.ts +104 -0
- package/templates/admin-shell/types/api/service.d.ts +51 -0
- package/templates/admin-shell/types/api/system-manage.d.ts +160 -0
- package/templates/admin-shell/types/app/common.d.ts +31 -0
- package/templates/admin-shell/types/app/global.d.ts +71 -0
- package/templates/admin-shell/types/app/menu.d.ts +57 -0
- package/templates/admin-shell/types/app/router.d.ts +201 -0
- package/templates/admin-shell/types/app/storage.d.ts +10 -0
- package/templates/admin-shell/types/app/union-key.d.ts +156 -0
- package/templates/admin-shell/types/locales/i18n.d.ts +135 -0
- package/templates/admin-shell/ui/antd/components/AppTree.tsx +62 -0
- package/templates/admin-shell/ui/antd/components/BeyondHiding.tsx +42 -0
- package/templates/admin-shell/ui/antd/components/ButtonIcon.tsx +123 -0
- package/templates/admin-shell/ui/antd/components/ButtonLink.tsx +30 -0
- package/templates/admin-shell/ui/antd/components/ErrorBoundary.tsx +45 -0
- package/templates/admin-shell/ui/antd/components/ExceptionBase.tsx +69 -0
- package/templates/admin-shell/ui/antd/components/FullScreen.tsx +33 -0
- package/templates/admin-shell/ui/antd/components/PinToggler.tsx +35 -0
- package/templates/admin-shell/ui/antd/components/ReloadButton.tsx +20 -0
- package/templates/admin-shell/ui/antd/components/index.ts +12 -0
- package/templates/admin-shell/ui/antd/components/styles/button-icon-animations.css +246 -0
- package/templates/admin-shell/ui/antd/index.ts +1 -0
- package/templates/admin-shell/ui/antd/styles.d.ts +1 -0
- package/templates/admin-shell/ui/compose/animate-feature.ts +5 -0
- package/templates/admin-shell/ui/compose/components/BetterScroll.tsx +51 -0
- package/templates/admin-shell/ui/compose/components/DarkModeContainer.tsx +22 -0
- package/templates/admin-shell/ui/compose/components/FlipText.tsx +41 -0
- package/templates/admin-shell/ui/compose/components/I18nLabel.tsx +18 -0
- package/templates/admin-shell/ui/compose/components/LazyAnimate.tsx +10 -0
- package/templates/admin-shell/ui/compose/components/LookForward.tsx +24 -0
- package/templates/admin-shell/ui/compose/components/NumberTicker.tsx +105 -0
- package/templates/admin-shell/ui/compose/components/Portal.tsx +74 -0
- package/templates/admin-shell/ui/compose/components/SvgIcon.tsx +39 -0
- package/templates/admin-shell/ui/compose/components/TypingAnimation.tsx +83 -0
- package/templates/admin-shell/ui/compose/components/WaveBg.tsx +56 -0
- package/templates/admin-shell/ui/compose/components/index.ts +11 -0
- package/templates/admin-shell/ui/compose/index.ts +2 -0
- package/templates/admin-shell/ui/compose/table/DragContent.tsx +239 -0
- package/templates/admin-shell/ui/compose/table/TableHeaderOperation.tsx +210 -0
- package/templates/admin-shell/ui/compose/table/hooks.ts +196 -0
- package/templates/admin-shell/ui/compose/table/index.ts +16 -0
- package/templates/admin-shell/ui/compose/table/types.ts +244 -0
- package/templates/admin-shell/ui/compose/table/use-table-operate.ts +136 -0
- package/templates/admin-shell/ui/compose/table/use-table-scroll.ts +49 -0
- package/templates/admin-shell/ui/compose/table/use-table.ts +303 -0
- package/templates/admin.meta.json +756 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import type { AnyRoute } from '@tanstack/react-router';
|
|
2
|
+
|
|
3
|
+
import type { AdminLayoutsDynamicRoutes } from '../../setup';
|
|
4
|
+
import { normalizePath } from './menu-generator';
|
|
5
|
+
|
|
6
|
+
export interface CreateAdminDynamicRouteLoaderOptions {
|
|
7
|
+
/** Load raw backend routes from the consuming app. */
|
|
8
|
+
loadBackendRoutes: () => Promise<Api.Route.BackendRouteResponse>;
|
|
9
|
+
/** TanStack Router route tree generated by the consuming app. */
|
|
10
|
+
routeTree: AnyRoute;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface NormalizeBackendRouteResponseOptions {
|
|
14
|
+
/** TanStack Router route tree used to filter unavailable backend routes. */
|
|
15
|
+
routeTree: AnyRoute;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function collectAvailableRoutePaths(route: AnyRoute) {
|
|
19
|
+
const paths = new Set<string>();
|
|
20
|
+
|
|
21
|
+
function walk(currentRoute: AnyRoute) {
|
|
22
|
+
const fullPath = normalizePath(currentRoute.fullPath ?? '');
|
|
23
|
+
|
|
24
|
+
if (fullPath) {
|
|
25
|
+
paths.add(fullPath);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const children = currentRoute.children as AnyRoute[] | undefined;
|
|
29
|
+
children?.forEach(child => {
|
|
30
|
+
walk(child);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
walk(route);
|
|
35
|
+
|
|
36
|
+
return paths;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function toParentId(parentId?: number | string | null) {
|
|
40
|
+
if (parentId === null || parentId === undefined) return null;
|
|
41
|
+
|
|
42
|
+
return String(parentId);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function toRouteTab(handle: Api.Route.BackendRouteHandle) {
|
|
46
|
+
return {
|
|
47
|
+
fixedIndex: handle.fixedIndexInTab,
|
|
48
|
+
multi: handle.multiTab
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function isBackendRoute(route: Api.Route.BackendRoute | null): route is Api.Route.BackendRoute {
|
|
53
|
+
return route !== null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function createBackendRouteNormalizer(routeTree: AnyRoute) {
|
|
57
|
+
const availableRoutePaths = collectAvailableRoutePaths(routeTree);
|
|
58
|
+
|
|
59
|
+
function normalizeBackendPath(path: string) {
|
|
60
|
+
return normalizePath(path.replaceAll(/:([A-Za-z0-9_]+)/g, '$$$1'));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function toRoutePath(path: string) {
|
|
64
|
+
return normalizeBackendPath(path) as Router.RoutePath;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function toAvailableRoutePath(path?: string | null) {
|
|
68
|
+
if (!path) return null;
|
|
69
|
+
|
|
70
|
+
const routePath = toRoutePath(path);
|
|
71
|
+
|
|
72
|
+
return availableRoutePaths.has(routePath) ? routePath : null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function toBackendRouteChildren(route: Api.Route.BackendRoutePayload) {
|
|
76
|
+
const children = route.children?.map(toBackendRoute).filter(isBackendRoute) ?? [];
|
|
77
|
+
|
|
78
|
+
return children.length ? children : [];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function toRouteMenu(handle: Api.Route.BackendRouteHandle) {
|
|
82
|
+
return {
|
|
83
|
+
activeMenu: toAvailableRoutePath(handle.activeMenu),
|
|
84
|
+
badge: handle.badge,
|
|
85
|
+
extra: handle.extra,
|
|
86
|
+
hide: handle.hideInMenu,
|
|
87
|
+
icon: handle.icon,
|
|
88
|
+
localIcon: handle.localIcon,
|
|
89
|
+
order: handle.order,
|
|
90
|
+
type: handle.type
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function toBackendRoute(route: Api.Route.BackendRoutePayload): Api.Route.BackendRoute | null {
|
|
95
|
+
const path = toRoutePath(route.path);
|
|
96
|
+
|
|
97
|
+
if (!availableRoutePaths.has(path)) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const handle = route.handle ?? route.meta ?? {};
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
id: String(route.id ?? route.name ?? path),
|
|
105
|
+
children: toBackendRouteChildren(route),
|
|
106
|
+
href: handle.href,
|
|
107
|
+
i18nKey: handle.i18nKey,
|
|
108
|
+
keepAlive: handle.keepAlive,
|
|
109
|
+
layout: route.layout,
|
|
110
|
+
menu: toRouteMenu(handle),
|
|
111
|
+
parentId: toParentId(route.parentId),
|
|
112
|
+
path,
|
|
113
|
+
permissions: handle.roles,
|
|
114
|
+
query: handle.query,
|
|
115
|
+
tab: toRouteTab(handle),
|
|
116
|
+
title: handle.title ?? route.name,
|
|
117
|
+
url: handle.url
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return function normalizeRouteResponse(routeData: Api.Route.BackendRouteResponse): AdminLayoutsDynamicRoutes {
|
|
122
|
+
return {
|
|
123
|
+
home: toAvailableRoutePath(routeData.home),
|
|
124
|
+
routes: routeData.routes.map(toBackendRoute).filter(isBackendRoute)
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function normalizeBackendRouteResponse(
|
|
130
|
+
routeData: Api.Route.BackendRouteResponse,
|
|
131
|
+
options: NormalizeBackendRouteResponseOptions
|
|
132
|
+
) {
|
|
133
|
+
return createBackendRouteNormalizer(options.routeTree)(routeData);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function createAdminDynamicRouteLoader(options: CreateAdminDynamicRouteLoaderOptions) {
|
|
137
|
+
const { loadBackendRoutes, routeTree } = options;
|
|
138
|
+
|
|
139
|
+
return async function loadAdminDynamicRoutes() {
|
|
140
|
+
const normalizeBackendRoutes = createBackendRouteNormalizer(routeTree);
|
|
141
|
+
|
|
142
|
+
const routeData = await loadBackendRoutes();
|
|
143
|
+
|
|
144
|
+
return normalizeBackendRoutes(routeData);
|
|
145
|
+
};
|
|
146
|
+
}
|
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
import type { AnyRoute } from '@tanstack/react-router';
|
|
2
|
+
|
|
3
|
+
import { getAdminLayoutsOptions, getConfiguredCategoryKeys, getMenuCategoryKey } from '../../setup';
|
|
4
|
+
import { hasRoutePermission } from './permissions';
|
|
5
|
+
|
|
6
|
+
export interface GeneratedMenu {
|
|
7
|
+
badge?: Router.MenuBadge | null;
|
|
8
|
+
children?: GeneratedMenu[];
|
|
9
|
+
extra?: Router.Extra | null;
|
|
10
|
+
href?: string | null;
|
|
11
|
+
i18nKey?: I18n.I18nKey | null;
|
|
12
|
+
icon?: string | null;
|
|
13
|
+
key: string;
|
|
14
|
+
localIcon?: string | null;
|
|
15
|
+
order?: number | null;
|
|
16
|
+
path?: Router.RoutePath;
|
|
17
|
+
title?: string | null;
|
|
18
|
+
type?: string;
|
|
19
|
+
url?: string | null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type GeneratedMenus = Map<string, GeneratedMenu[]>;
|
|
23
|
+
|
|
24
|
+
export interface GenerateMenuOptions {
|
|
25
|
+
backendRoutes?: Api.Route.BackendRoute[];
|
|
26
|
+
home?: Router.RoutePath | null;
|
|
27
|
+
userInfo?: Api.Auth.UserInfo | null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface GenerateMenuResult {
|
|
31
|
+
allMenus: GeneratedMenus;
|
|
32
|
+
home: Router.RoutePath;
|
|
33
|
+
quickReferenceMenus: Menu.QuickReferenceMenus;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface ExtraMenuOptions {
|
|
37
|
+
config: Partial<Api.Route.BackendRoute>;
|
|
38
|
+
depth?: number;
|
|
39
|
+
parentKeys?: string[];
|
|
40
|
+
quickReferenceMenuMap: Menu.QuickReferenceMenuMap;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface StaticChildMenusOptions {
|
|
44
|
+
depth: number;
|
|
45
|
+
normalizedPath: Router.RoutePath;
|
|
46
|
+
parentKeys: string[];
|
|
47
|
+
quickReferenceMenuMap: Menu.QuickReferenceMenuMap;
|
|
48
|
+
route: AnyRoute;
|
|
49
|
+
userInfo?: Api.Auth.UserInfo | null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function normalizePath(path: string): string {
|
|
53
|
+
return path.endsWith('/') && path !== '/' ? path.slice(0, -1) : path;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function findLayoutRoute(layoutIds: Router.RouteId[]): AnyRoute[] {
|
|
57
|
+
const menuRoutes: AnyRoute[] = [];
|
|
58
|
+
const { routeTree } = getAdminLayoutsOptions();
|
|
59
|
+
const firstLevelRoutes = routeTree.children as AnyRoute[] | undefined;
|
|
60
|
+
|
|
61
|
+
firstLevelRoutes?.forEach(firstLevelRoute => {
|
|
62
|
+
if (layoutIds.includes(firstLevelRoute.id)) {
|
|
63
|
+
menuRoutes.push(firstLevelRoute);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
return menuRoutes;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function sortMenus(menus: GeneratedMenu[]) {
|
|
71
|
+
return menus.toSorted((a, b) => {
|
|
72
|
+
const orderA = a.order ?? 0;
|
|
73
|
+
const orderB = b.order ?? 0;
|
|
74
|
+
return orderA - orderB;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function isGeneratedMenu(menu: GeneratedMenu | null): menu is GeneratedMenu {
|
|
79
|
+
return Boolean(menu);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function createEmptyCategoryMaps() {
|
|
83
|
+
const allMenus = new Map<string, GeneratedMenu[]>();
|
|
84
|
+
const quickReferenceMenus = new Map<string, Menu.QuickReferenceMenuMap>();
|
|
85
|
+
|
|
86
|
+
getConfiguredCategoryKeys().forEach(categoryKey => {
|
|
87
|
+
allMenus.set(categoryKey, []);
|
|
88
|
+
quickReferenceMenus.set(categoryKey, new Map());
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
allMenus,
|
|
93
|
+
quickReferenceMenus
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function getMenuNodeConfigs(routeId: Router.RouteId) {
|
|
98
|
+
const { menuNodeCallback } = getAdminLayoutsOptions();
|
|
99
|
+
|
|
100
|
+
return menuNodeCallback?.(routeId) ?? [];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** 菜单生成器 */
|
|
104
|
+
class MenuGenerator {
|
|
105
|
+
generate(options: GenerateMenuOptions = {}): GenerateMenuResult {
|
|
106
|
+
const { routeMode } = getAdminLayoutsOptions();
|
|
107
|
+
|
|
108
|
+
if (routeMode === 'dynamic') {
|
|
109
|
+
return this.generateDynamicMenus(options);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return this.generateStaticMenus(options);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
private generateStaticMenus(options: GenerateMenuOptions): GenerateMenuResult {
|
|
116
|
+
const { defaultHome, menuCategories } = getAdminLayoutsOptions();
|
|
117
|
+
const { allMenus, quickReferenceMenus } = createEmptyCategoryMaps();
|
|
118
|
+
const menuCategoryLayouts = getConfiguredCategoryKeys().map(layout => menuCategories[layout].layout);
|
|
119
|
+
const layoutRoutes = findLayoutRoute(menuCategoryLayouts);
|
|
120
|
+
|
|
121
|
+
layoutRoutes.forEach(layoutRoute => {
|
|
122
|
+
const menuCategoryKey = getMenuCategoryKey(layoutRoute.id);
|
|
123
|
+
|
|
124
|
+
if (!menuCategoryKey) return;
|
|
125
|
+
|
|
126
|
+
const quickReferenceMenuMap = quickReferenceMenus.get(menuCategoryKey) ?? new Map();
|
|
127
|
+
const menus = this.generateStaticLayoutMenus(layoutRoute, quickReferenceMenuMap, options.userInfo);
|
|
128
|
+
|
|
129
|
+
quickReferenceMenus.set(menuCategoryKey, quickReferenceMenuMap);
|
|
130
|
+
allMenus.set(menuCategoryKey, menus);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
allMenus,
|
|
135
|
+
home: defaultHome,
|
|
136
|
+
quickReferenceMenus
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private generateDynamicMenus(options: GenerateMenuOptions): GenerateMenuResult {
|
|
141
|
+
const { defaultHome } = getAdminLayoutsOptions();
|
|
142
|
+
const { allMenus, quickReferenceMenus } = createEmptyCategoryMaps();
|
|
143
|
+
const defaultCategoryKey = getConfiguredCategoryKeys()[0];
|
|
144
|
+
|
|
145
|
+
options.backendRoutes?.forEach(route => {
|
|
146
|
+
const categoryKey = route.layout ?? defaultCategoryKey;
|
|
147
|
+
|
|
148
|
+
if (!categoryKey) return;
|
|
149
|
+
|
|
150
|
+
const quickReferenceMenuMap = quickReferenceMenus.get(categoryKey) ?? new Map();
|
|
151
|
+
const menu = this.transformBackendRouteToMenu(route, quickReferenceMenuMap, options.userInfo);
|
|
152
|
+
|
|
153
|
+
if (menu) {
|
|
154
|
+
allMenus.set(categoryKey, [...(allMenus.get(categoryKey) ?? []), menu]);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
quickReferenceMenus.set(categoryKey, quickReferenceMenuMap);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
allMenus.forEach((menus, categoryKey) => {
|
|
161
|
+
allMenus.set(categoryKey, sortMenus(menus));
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
return {
|
|
165
|
+
allMenus,
|
|
166
|
+
home: options.home ?? defaultHome,
|
|
167
|
+
quickReferenceMenus
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private generateStaticLayoutMenus(
|
|
172
|
+
layoutRoute: AnyRoute,
|
|
173
|
+
quickReferenceMenuMap: Menu.QuickReferenceMenuMap,
|
|
174
|
+
userInfo?: Api.Auth.UserInfo | null
|
|
175
|
+
) {
|
|
176
|
+
const children = layoutRoute.children as AnyRoute[] | undefined;
|
|
177
|
+
const menuList = children
|
|
178
|
+
? children
|
|
179
|
+
.map(route => this.transformStaticRouteToMenu(route, quickReferenceMenuMap, userInfo))
|
|
180
|
+
.filter(isGeneratedMenu)
|
|
181
|
+
: [];
|
|
182
|
+
|
|
183
|
+
const extraMenus = getMenuNodeConfigs(layoutRoute.id as Router.RouteId);
|
|
184
|
+
|
|
185
|
+
if (extraMenus.length) {
|
|
186
|
+
menuList.push(
|
|
187
|
+
...extraMenus
|
|
188
|
+
.map(menuConfig => this.createExtraMenu({ config: menuConfig, quickReferenceMenuMap }))
|
|
189
|
+
.filter(isGeneratedMenu)
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return sortMenus(menuList as GeneratedMenu[]);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// eslint-disable-next-line complexity, max-params
|
|
197
|
+
private transformStaticRouteToMenu(
|
|
198
|
+
route: AnyRoute,
|
|
199
|
+
quickReferenceMenuMap: Menu.QuickReferenceMenuMap,
|
|
200
|
+
userInfo?: Api.Auth.UserInfo | null,
|
|
201
|
+
parentKeys: string[] = [],
|
|
202
|
+
depth: number = 0
|
|
203
|
+
): GeneratedMenu | null {
|
|
204
|
+
const { staticData } = route.options;
|
|
205
|
+
|
|
206
|
+
if (!staticData || !hasRoutePermission(staticData, userInfo)) {
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const normalizedPath = normalizePath(route.fullPath) as Router.RoutePath;
|
|
211
|
+
const data: Menu.QuickReferenceMenu = {
|
|
212
|
+
id: route.id,
|
|
213
|
+
i18nKey: staticData.i18nKey,
|
|
214
|
+
key: normalizedPath,
|
|
215
|
+
href: staticData.href,
|
|
216
|
+
keepAlive: staticData.keepAlive,
|
|
217
|
+
menu: staticData.menu,
|
|
218
|
+
parentKeys,
|
|
219
|
+
path: normalizedPath,
|
|
220
|
+
query: staticData.query,
|
|
221
|
+
tab: staticData.tab,
|
|
222
|
+
title: staticData.title,
|
|
223
|
+
url: staticData.url,
|
|
224
|
+
depth
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
quickReferenceMenuMap.set(normalizedPath, data);
|
|
228
|
+
|
|
229
|
+
if (staticData.menu?.hide) {
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const { defaultIcon } = getAdminLayoutsOptions();
|
|
234
|
+
const { badge, extra, icon = defaultIcon, localIcon, order = 0, type = 'item' } = staticData.menu ?? {};
|
|
235
|
+
const menuType = type ?? 'item';
|
|
236
|
+
const menu: GeneratedMenu = {
|
|
237
|
+
badge,
|
|
238
|
+
extra,
|
|
239
|
+
href: staticData.href,
|
|
240
|
+
i18nKey: staticData.i18nKey,
|
|
241
|
+
icon,
|
|
242
|
+
key: normalizedPath,
|
|
243
|
+
localIcon,
|
|
244
|
+
order,
|
|
245
|
+
path: normalizedPath,
|
|
246
|
+
title: staticData.title,
|
|
247
|
+
type: menuType,
|
|
248
|
+
url: staticData.url
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
const childMenus = this.generateStaticChildMenus({
|
|
252
|
+
depth,
|
|
253
|
+
normalizedPath,
|
|
254
|
+
parentKeys,
|
|
255
|
+
quickReferenceMenuMap,
|
|
256
|
+
route,
|
|
257
|
+
userInfo
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
if (childMenus.length) {
|
|
261
|
+
menu.children = childMenus;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return menu;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
private generateStaticChildMenus(options: StaticChildMenusOptions) {
|
|
268
|
+
const { depth, normalizedPath, parentKeys, quickReferenceMenuMap, route, userInfo } = options;
|
|
269
|
+
const childMenus: GeneratedMenu[] = [];
|
|
270
|
+
|
|
271
|
+
if (route.children && Object.keys(route.children).length > 0) {
|
|
272
|
+
Object.values(route.children).forEach(childRoute => {
|
|
273
|
+
const childMenu = this.transformStaticRouteToMenu(
|
|
274
|
+
childRoute as AnyRoute,
|
|
275
|
+
quickReferenceMenuMap,
|
|
276
|
+
userInfo,
|
|
277
|
+
[...parentKeys, normalizedPath],
|
|
278
|
+
depth + 1
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
if (childMenu) {
|
|
282
|
+
childMenus.push(childMenu);
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const extraMenus = getMenuNodeConfigs(route.id as Router.RouteId);
|
|
288
|
+
|
|
289
|
+
if (extraMenus.length) {
|
|
290
|
+
childMenus.push(
|
|
291
|
+
...extraMenus
|
|
292
|
+
.map(menuConfig =>
|
|
293
|
+
this.createExtraMenu({
|
|
294
|
+
config: menuConfig,
|
|
295
|
+
depth: depth + 1,
|
|
296
|
+
parentKeys: [...parentKeys, normalizedPath],
|
|
297
|
+
quickReferenceMenuMap
|
|
298
|
+
})
|
|
299
|
+
)
|
|
300
|
+
.filter(isGeneratedMenu)
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return sortMenus(childMenus);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// eslint-disable-next-line complexity, max-params
|
|
308
|
+
private transformBackendRouteToMenu(
|
|
309
|
+
route: Api.Route.BackendRoute,
|
|
310
|
+
quickReferenceMenuMap: Menu.QuickReferenceMenuMap,
|
|
311
|
+
userInfo?: Api.Auth.UserInfo | null,
|
|
312
|
+
parentKeys: string[] = [],
|
|
313
|
+
depth: number = 0
|
|
314
|
+
): GeneratedMenu | null {
|
|
315
|
+
if (!hasRoutePermission(route, userInfo)) {
|
|
316
|
+
return null;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
const { defaultIcon } = getAdminLayoutsOptions();
|
|
320
|
+
const path = normalizePath(route.path) as Router.RoutePath;
|
|
321
|
+
const data: Menu.QuickReferenceMenu = {
|
|
322
|
+
...route,
|
|
323
|
+
key: path,
|
|
324
|
+
parentKeys,
|
|
325
|
+
path,
|
|
326
|
+
depth
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
quickReferenceMenuMap.set(path, data);
|
|
330
|
+
|
|
331
|
+
if (route.menu?.hide) {
|
|
332
|
+
return null;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const { badge, extra, icon = defaultIcon, localIcon, order = 0, type = 'item' } = route.menu ?? {};
|
|
336
|
+
const menuType = type ?? 'item';
|
|
337
|
+
const menu: GeneratedMenu = {
|
|
338
|
+
badge,
|
|
339
|
+
extra,
|
|
340
|
+
href: route.href,
|
|
341
|
+
i18nKey: route.i18nKey,
|
|
342
|
+
icon,
|
|
343
|
+
key: path,
|
|
344
|
+
localIcon,
|
|
345
|
+
order,
|
|
346
|
+
path,
|
|
347
|
+
title: route.title,
|
|
348
|
+
type: menuType,
|
|
349
|
+
url: route.url
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
const children = route.children
|
|
353
|
+
?.map(child =>
|
|
354
|
+
this.transformBackendRouteToMenu(child, quickReferenceMenuMap, userInfo, [...parentKeys, path], depth + 1)
|
|
355
|
+
)
|
|
356
|
+
.filter(isGeneratedMenu);
|
|
357
|
+
const childMenus = children ?? [];
|
|
358
|
+
|
|
359
|
+
const extraMenus = getMenuNodeConfigs(route.id as Router.RouteId);
|
|
360
|
+
|
|
361
|
+
if (extraMenus.length) {
|
|
362
|
+
childMenus.push(
|
|
363
|
+
...extraMenus
|
|
364
|
+
.map(menuConfig =>
|
|
365
|
+
this.createExtraMenu({
|
|
366
|
+
config: menuConfig,
|
|
367
|
+
depth: depth + 1,
|
|
368
|
+
parentKeys: [...parentKeys, path],
|
|
369
|
+
quickReferenceMenuMap
|
|
370
|
+
})
|
|
371
|
+
)
|
|
372
|
+
.filter(isGeneratedMenu)
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
if (childMenus.length) {
|
|
377
|
+
menu.children = sortMenus(childMenus);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
return menu;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
private createExtraMenu(options: ExtraMenuOptions): GeneratedMenu | null {
|
|
384
|
+
const { defaultIcon } = getAdminLayoutsOptions();
|
|
385
|
+
const { config, depth = 0, parentKeys = [], quickReferenceMenuMap } = options;
|
|
386
|
+
const { badge, icon = defaultIcon, localIcon, order = 0, type = 'item' } = config.menu ?? {};
|
|
387
|
+
const menuType = type ?? 'item';
|
|
388
|
+
|
|
389
|
+
if (menuType === 'divider') {
|
|
390
|
+
return {
|
|
391
|
+
key: config.id ?? `divider-${parentKeys.join('-')}-${order ?? 0}`,
|
|
392
|
+
order,
|
|
393
|
+
type: 'divider'
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
if (!config.path) return null;
|
|
398
|
+
|
|
399
|
+
const path = normalizePath(config.path) as Router.RoutePath;
|
|
400
|
+
const data: Menu.QuickReferenceMenu = {
|
|
401
|
+
...(config as Api.Route.BackendRoute),
|
|
402
|
+
key: path,
|
|
403
|
+
parentKeys,
|
|
404
|
+
path,
|
|
405
|
+
depth
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
quickReferenceMenuMap.set(path, data);
|
|
409
|
+
|
|
410
|
+
const menu: GeneratedMenu = {
|
|
411
|
+
badge,
|
|
412
|
+
extra: config.menu?.extra,
|
|
413
|
+
href: config.href,
|
|
414
|
+
i18nKey: config.i18nKey,
|
|
415
|
+
icon,
|
|
416
|
+
key: path,
|
|
417
|
+
localIcon,
|
|
418
|
+
order,
|
|
419
|
+
path,
|
|
420
|
+
title: config.title,
|
|
421
|
+
type: menuType,
|
|
422
|
+
url: config.url
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
const children = config.children
|
|
426
|
+
?.map(child =>
|
|
427
|
+
this.createExtraMenu({
|
|
428
|
+
config: child,
|
|
429
|
+
depth: depth + 1,
|
|
430
|
+
parentKeys: [...parentKeys, path],
|
|
431
|
+
quickReferenceMenuMap
|
|
432
|
+
})
|
|
433
|
+
)
|
|
434
|
+
.filter(isGeneratedMenu);
|
|
435
|
+
|
|
436
|
+
if (children?.length) {
|
|
437
|
+
menu.children = sortMenus(children);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
return menu;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
export const menuGenerator = new MenuGenerator();
|