@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,196 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
HookTableConfig,
|
|
5
|
+
HookTableResult,
|
|
6
|
+
PaginationData,
|
|
7
|
+
TableColumnCheck,
|
|
8
|
+
TableDataWithIndex
|
|
9
|
+
} from './types';
|
|
10
|
+
|
|
11
|
+
const DEFAULT_PAGE = 1;
|
|
12
|
+
const DEFAULT_PAGE_SIZE = 10;
|
|
13
|
+
|
|
14
|
+
/** 核心表格 Hook,负责查询参数、React Query 请求、分页结果和列设置状态。 */
|
|
15
|
+
export function useHookTable<Params, Response, T, Column>(
|
|
16
|
+
config: HookTableConfig<Params, Response, T, Column>
|
|
17
|
+
): HookTableResult<Params, T, Column> {
|
|
18
|
+
const {
|
|
19
|
+
apiParams,
|
|
20
|
+
columns: columnsFactory,
|
|
21
|
+
enabled = true,
|
|
22
|
+
getColumnChecks,
|
|
23
|
+
getColumns,
|
|
24
|
+
immediate = true,
|
|
25
|
+
isChangeURL = false,
|
|
26
|
+
onSearchParamsChange,
|
|
27
|
+
queryHook,
|
|
28
|
+
queryOptions,
|
|
29
|
+
resetParams,
|
|
30
|
+
transformer,
|
|
31
|
+
transformParams
|
|
32
|
+
} = config;
|
|
33
|
+
|
|
34
|
+
const initialSearchParamsRef = useRef(createSearchParams<Params>(apiParams));
|
|
35
|
+
const resetSearchParamsRef = useRef(createSearchParams<Params>(resetParams ?? apiParams));
|
|
36
|
+
const onFetchedRef = useRef(config.onFetched);
|
|
37
|
+
|
|
38
|
+
onFetchedRef.current = config.onFetched;
|
|
39
|
+
|
|
40
|
+
const [searchParams, setSearchParams] = useState<Partial<Params>>(initialSearchParamsRef.current);
|
|
41
|
+
const [queryEnabled, setQueryEnabled] = useState(immediate);
|
|
42
|
+
const [columnChecks, setColumnChecks] = useState<TableColumnCheck[]>(() => getColumnChecks(columnsFactory()));
|
|
43
|
+
|
|
44
|
+
const allColumns = columnsFactory();
|
|
45
|
+
const columns = getColumns(allColumns, columnChecks);
|
|
46
|
+
const requestParams = resolveRequestParams<Params>(searchParams, transformParams);
|
|
47
|
+
|
|
48
|
+
const query = queryHook<PaginationData<TableDataWithIndex<T>>>(requestParams, {
|
|
49
|
+
...queryOptions,
|
|
50
|
+
enabled: enabled && queryEnabled,
|
|
51
|
+
select: response => {
|
|
52
|
+
return withTableIndex(transformer(response));
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const paginationData = query.data ?? createEmptyPaginationData<T>();
|
|
57
|
+
const empty = !query.isFetching && paginationData.data.length === 0;
|
|
58
|
+
const loading = query.isFetching;
|
|
59
|
+
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (!query.data) return;
|
|
62
|
+
|
|
63
|
+
const onFetched = onFetchedRef.current;
|
|
64
|
+
|
|
65
|
+
if (!onFetched) return;
|
|
66
|
+
|
|
67
|
+
Promise.resolve(onFetched(query.data)).catch(() => undefined);
|
|
68
|
+
}, [query.data]);
|
|
69
|
+
|
|
70
|
+
/** 重新请求当前查询。 */
|
|
71
|
+
async function getData() {
|
|
72
|
+
setQueryEnabled(true);
|
|
73
|
+
await query.refetch();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** 合并更新查询参数。 */
|
|
77
|
+
function updateSearchParams(params: Partial<Params>) {
|
|
78
|
+
commitSearchParams({ ...searchParams, ...params });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** 用默认参数重置查询。 */
|
|
82
|
+
function resetSearchParams() {
|
|
83
|
+
commitSearchParams(resetSearchParamsRef.current);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** 重新生成列设置,并保留已有显隐、固定和排序偏好。 */
|
|
87
|
+
function reloadColumns() {
|
|
88
|
+
const nextChecks = getColumnChecks(columnsFactory());
|
|
89
|
+
setColumnChecks(mergeColumnChecks(columnChecks, nextChecks));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function commitSearchParams(nextParams: Partial<Params>) {
|
|
93
|
+
const formattedParams = formatSearchParams(nextParams);
|
|
94
|
+
|
|
95
|
+
setSearchParams(formattedParams);
|
|
96
|
+
setQueryEnabled(true);
|
|
97
|
+
|
|
98
|
+
if (isChangeURL) {
|
|
99
|
+
onSearchParamsChange?.(formattedParams);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
columnChecks,
|
|
105
|
+
columns,
|
|
106
|
+
data: paginationData.data,
|
|
107
|
+
empty,
|
|
108
|
+
getData,
|
|
109
|
+
loading,
|
|
110
|
+
pageNum: paginationData.pageNum,
|
|
111
|
+
pageSize: paginationData.pageSize,
|
|
112
|
+
query,
|
|
113
|
+
reloadColumns,
|
|
114
|
+
resetSearchParams,
|
|
115
|
+
searchParams,
|
|
116
|
+
setColumnChecks,
|
|
117
|
+
total: paginationData.total,
|
|
118
|
+
updateSearchParams
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** 移除查询参数中的空值,保留 false、0 和空字符串。 */
|
|
123
|
+
export function formatSearchParams<T>(params: Partial<T> = {}) {
|
|
124
|
+
const entries = Object.entries(params as Record<string, unknown>).filter(([, value]) => {
|
|
125
|
+
return value !== null && value !== undefined;
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
return Object.fromEntries(entries) as Partial<T>;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function createSearchParams<T>(params?: Partial<T>) {
|
|
132
|
+
return formatSearchParams<T>({
|
|
133
|
+
current: DEFAULT_PAGE,
|
|
134
|
+
size: DEFAULT_PAGE_SIZE,
|
|
135
|
+
...params
|
|
136
|
+
} as unknown as Partial<T>);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function resolveRequestParams<Params>(
|
|
140
|
+
searchParams: Partial<Params>,
|
|
141
|
+
transformParams?: (params: Params) => Params
|
|
142
|
+
) {
|
|
143
|
+
const formattedParams = formatSearchParams(searchParams) as Params;
|
|
144
|
+
|
|
145
|
+
if (!transformParams) {
|
|
146
|
+
return formattedParams;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return transformParams(formattedParams);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function createEmptyPaginationData<T>(): PaginationData<TableDataWithIndex<T>> {
|
|
153
|
+
return {
|
|
154
|
+
data: [],
|
|
155
|
+
pageNum: DEFAULT_PAGE,
|
|
156
|
+
pageSize: DEFAULT_PAGE_SIZE,
|
|
157
|
+
total: 0
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function withTableIndex<T>(data: PaginationData<T>): PaginationData<TableDataWithIndex<T>> {
|
|
162
|
+
const { data: records, pageNum, pageSize, total } = data;
|
|
163
|
+
|
|
164
|
+
return {
|
|
165
|
+
data: records.map((item, index) => {
|
|
166
|
+
return {
|
|
167
|
+
...item,
|
|
168
|
+
index: (pageNum - 1) * pageSize + index + 1
|
|
169
|
+
} as TableDataWithIndex<T>;
|
|
170
|
+
}),
|
|
171
|
+
pageNum,
|
|
172
|
+
pageSize,
|
|
173
|
+
total
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function mergeColumnChecks(currentChecks: TableColumnCheck[], nextChecks: TableColumnCheck[]) {
|
|
178
|
+
const currentMap = new Map(currentChecks.map(item => [item.key, item]));
|
|
179
|
+
const orderMap = new Map(currentChecks.map((item, index) => [item.key, index]));
|
|
180
|
+
const fallbackOrder = nextChecks.length;
|
|
181
|
+
|
|
182
|
+
return nextChecks
|
|
183
|
+
.map((item, index) => {
|
|
184
|
+
const current = currentMap.get(item.key);
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
...item,
|
|
188
|
+
checked: current?.checked ?? item.checked,
|
|
189
|
+
fixed: current?.fixed ?? item.fixed,
|
|
190
|
+
visible: current?.visible ?? item.visible,
|
|
191
|
+
__order: orderMap.get(item.key) ?? fallbackOrder + index
|
|
192
|
+
};
|
|
193
|
+
})
|
|
194
|
+
.toSorted((a, b) => a.__order - b.__order)
|
|
195
|
+
.map(({ __order: _order, ...item }) => item);
|
|
196
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// 导出组件
|
|
2
|
+
export { default as DragContent } from './DragContent';
|
|
3
|
+
export * from './hooks';
|
|
4
|
+
export { default as TableHeaderOperation } from './TableHeaderOperation';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Table Features
|
|
8
|
+
*
|
|
9
|
+
* 提供完整的表格功能模块
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export * from './types';
|
|
13
|
+
export * from './use-table';
|
|
14
|
+
|
|
15
|
+
export * from './use-table-operate';
|
|
16
|
+
export * from './use-table-scroll';
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import type { QueryKey, UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { FormInstance, TablePaginationConfig, TableProps } from 'antd';
|
|
3
|
+
import type { ColumnsType } from 'antd/es/table';
|
|
4
|
+
import type { Key, ReactNode } from 'react';
|
|
5
|
+
|
|
6
|
+
/** 表格接口函数类型。 */
|
|
7
|
+
export type TableApiFn<Params = any, Response = PaginatingQueryRecord<any>> = (params: Params) => Promise<Response>;
|
|
8
|
+
|
|
9
|
+
/** 后端分页列表的最小结构。 */
|
|
10
|
+
export interface PaginatingQueryRecord<T = any> {
|
|
11
|
+
/** 当前页码。 */
|
|
12
|
+
current: number;
|
|
13
|
+
/** 数据列表。 */
|
|
14
|
+
records: T[];
|
|
15
|
+
/** 每页条数。 */
|
|
16
|
+
size: number;
|
|
17
|
+
/** 总条数。 */
|
|
18
|
+
total: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** 从分页接口响应中提取列表项类型。 */
|
|
22
|
+
export type GetTableData<A extends TableApiFn> =
|
|
23
|
+
Awaited<ReturnType<A>> extends PaginatingQueryRecord<infer T> ? T : never;
|
|
24
|
+
|
|
25
|
+
/** 从分页接口响应类型中提取列表项类型。 */
|
|
26
|
+
export type GetTableDataFromResponse<Response> = Response extends PaginatingQueryRecord<infer T> ? T : never;
|
|
27
|
+
|
|
28
|
+
/** 带序号的表格行数据。 */
|
|
29
|
+
export type TableDataWithIndex<T> = T & {
|
|
30
|
+
/** 当前查询结果中的连续序号。 */
|
|
31
|
+
index: number;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** Ant Design 表格列定义。 */
|
|
35
|
+
export type TableColumn<T = any> = ColumnsType<T>[number];
|
|
36
|
+
|
|
37
|
+
/** 表格列固定位置。 */
|
|
38
|
+
export type TableColumnFixed = 'left' | 'right' | 'unFixed';
|
|
39
|
+
|
|
40
|
+
/** 列设置面板中展示的列标题。 */
|
|
41
|
+
export type TableColumnCheckTitle = ReactNode | ((...args: any[]) => ReactNode);
|
|
42
|
+
|
|
43
|
+
/** 表格列设置项。 */
|
|
44
|
+
export interface TableColumnCheck {
|
|
45
|
+
/** 列是否参与表格渲染。 */
|
|
46
|
+
checked: boolean;
|
|
47
|
+
/** 列固定到左侧、右侧,或取消固定。 */
|
|
48
|
+
fixed: TableColumnFixed;
|
|
49
|
+
/** 列的稳定唯一标识。 */
|
|
50
|
+
key: string;
|
|
51
|
+
/** 列设置面板中展示的标题。 */
|
|
52
|
+
title: TableColumnCheckTitle;
|
|
53
|
+
/** 列是否出现在列设置面板中。 */
|
|
54
|
+
visible: boolean;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** 标准分页数据。 */
|
|
58
|
+
export interface PaginationData<T = any> {
|
|
59
|
+
/** 当前页数据。 */
|
|
60
|
+
data: T[];
|
|
61
|
+
/** 当前页码。 */
|
|
62
|
+
pageNum: number;
|
|
63
|
+
/** 每页条数。 */
|
|
64
|
+
pageSize: number;
|
|
65
|
+
/** 总条数。 */
|
|
66
|
+
total: number;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** 表格操作类型。 */
|
|
70
|
+
export type TableOperateType = 'add' | 'edit';
|
|
71
|
+
|
|
72
|
+
/** 表格行基础数据。 */
|
|
73
|
+
export interface TableData {
|
|
74
|
+
/** 表格行的稳定业务主键。 */
|
|
75
|
+
id: Key;
|
|
76
|
+
/** 业务字段。 */
|
|
77
|
+
[key: string]: any;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** 表格变化回调参数。 */
|
|
81
|
+
export type TableOnChange<T = any> = Parameters<NonNullable<TableProps<T>['onChange']>>;
|
|
82
|
+
|
|
83
|
+
/** 根据请求参数生成 React Query key。 */
|
|
84
|
+
export type TableQueryKeyBuilder<A extends TableApiFn> = (params: Parameters<A>[0]) => QueryKey;
|
|
85
|
+
|
|
86
|
+
/** 表格查询 Hook 可接收的 React Query 配置。 */
|
|
87
|
+
export type TableQueryHookOptions<Response, Data = Response> = Omit<
|
|
88
|
+
UseQueryOptions<Response, Error, Data, QueryKey>,
|
|
89
|
+
'queryFn' | 'queryKey'
|
|
90
|
+
>;
|
|
91
|
+
|
|
92
|
+
/** 表格查询 Hook 类型,消费侧负责声明 queryKey 和 queryFn。 */
|
|
93
|
+
export type TableQueryHook<Params, Response> = <Data = Response>(
|
|
94
|
+
params: Params,
|
|
95
|
+
options?: TableQueryHookOptions<Response, Data>
|
|
96
|
+
) => UseQueryResult<Data, Error>;
|
|
97
|
+
|
|
98
|
+
/** React Query 配置,enabled/select/queryKey/queryFn 由表格 Hook 和查询 Hook 接管。 */
|
|
99
|
+
export type TableQueryOptions<Response, T> = Omit<
|
|
100
|
+
TableQueryHookOptions<Response, PaginationData<TableDataWithIndex<T>>>,
|
|
101
|
+
'enabled' | 'queryFn' | 'queryKey' | 'select'
|
|
102
|
+
>;
|
|
103
|
+
|
|
104
|
+
/** 核心表格 Hook 配置。 */
|
|
105
|
+
export interface HookTableConfig<Params, Response, T, Column> {
|
|
106
|
+
/** 初始查询参数,通常包含分页和查询表单默认值。 */
|
|
107
|
+
apiParams?: Partial<Params>;
|
|
108
|
+
/** 表格列工厂,允许消费侧按权限或国际化重新生成列。 */
|
|
109
|
+
columns: () => Column[];
|
|
110
|
+
/** 外部业务是否允许发起查询。 */
|
|
111
|
+
enabled?: boolean;
|
|
112
|
+
/** 从列定义生成列设置项。 */
|
|
113
|
+
getColumnChecks: (columns: Column[]) => TableColumnCheck[];
|
|
114
|
+
/** 根据列设置项生成最终渲染列。 */
|
|
115
|
+
getColumns: (columns: Column[], checks: TableColumnCheck[]) => Column[];
|
|
116
|
+
/** 是否首次挂载后立即请求。 */
|
|
117
|
+
immediate?: boolean;
|
|
118
|
+
/** 是否把提交后的查询参数同步给外部路由。 */
|
|
119
|
+
isChangeURL?: boolean;
|
|
120
|
+
/** 查询完成后的业务回调。 */
|
|
121
|
+
onFetched?: (data: PaginationData<TableDataWithIndex<T>>) => Promise<void> | void;
|
|
122
|
+
/** 查询参数变化时的外部同步回调。 */
|
|
123
|
+
onSearchParamsChange?: (params: Partial<Params>) => void;
|
|
124
|
+
/** 根据当前查询参数创建 React Query 查询。 */
|
|
125
|
+
queryHook: TableQueryHook<Params, Response>;
|
|
126
|
+
/** 透传给 React Query 的附加配置。 */
|
|
127
|
+
queryOptions?: TableQueryOptions<Response, T>;
|
|
128
|
+
/** 重置查询时使用的参数。 */
|
|
129
|
+
resetParams?: Partial<Params>;
|
|
130
|
+
/** 把接口响应转换成标准分页数据。 */
|
|
131
|
+
transformer: (response: Response) => PaginationData<T>;
|
|
132
|
+
/** 接口请求前的参数转换。 */
|
|
133
|
+
transformParams?: (params: Params) => Params;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** 核心表格 Hook 返回值。 */
|
|
137
|
+
export interface HookTableResult<Params, T, Column> {
|
|
138
|
+
/** 可配置的列设置项。 */
|
|
139
|
+
columnChecks: TableColumnCheck[];
|
|
140
|
+
/** 最终传给表格组件的列。 */
|
|
141
|
+
columns: Column[];
|
|
142
|
+
/** 当前页数据。 */
|
|
143
|
+
data: TableDataWithIndex<T>[];
|
|
144
|
+
/** 当前查询是否为空结果。 */
|
|
145
|
+
empty: boolean;
|
|
146
|
+
/** 重新请求当前查询。 */
|
|
147
|
+
getData: () => Promise<void>;
|
|
148
|
+
/** 当前查询是否正在请求。 */
|
|
149
|
+
loading: boolean;
|
|
150
|
+
/** 当前页码。 */
|
|
151
|
+
pageNum: number;
|
|
152
|
+
/** 每页条数。 */
|
|
153
|
+
pageSize: number;
|
|
154
|
+
/** 底层 React Query 查询结果。 */
|
|
155
|
+
query: UseQueryResult<PaginationData<TableDataWithIndex<T>>, Error>;
|
|
156
|
+
/** 重新从列工厂生成列设置项,并保留用户设置。 */
|
|
157
|
+
reloadColumns: () => void;
|
|
158
|
+
/** 用默认参数重置查询。 */
|
|
159
|
+
resetSearchParams: () => void;
|
|
160
|
+
/** 当前已提交的查询参数。 */
|
|
161
|
+
searchParams: Partial<Params>;
|
|
162
|
+
/** 更新列设置项。 */
|
|
163
|
+
setColumnChecks: (checks: TableColumnCheck[]) => void;
|
|
164
|
+
/** 总条数。 */
|
|
165
|
+
total: number;
|
|
166
|
+
/** 合并更新查询参数。 */
|
|
167
|
+
updateSearchParams: (params: Partial<Params>) => void;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** 表格配置。 */
|
|
171
|
+
export interface TableConfig<Params, Response, T = GetTableDataFromResponse<Response>>
|
|
172
|
+
extends Omit<
|
|
173
|
+
TableProps<TableDataWithIndex<T>>,
|
|
174
|
+
'columns' | 'dataSource' | 'loading' | 'onChange' | 'pagination' | 'rowKey'
|
|
175
|
+
> {
|
|
176
|
+
/** 接口默认查询参数。 */
|
|
177
|
+
apiParams?: Partial<Params>;
|
|
178
|
+
/** Ant Design 表格列工厂。 */
|
|
179
|
+
columns: () => TableColumn<TableDataWithIndex<T>>[];
|
|
180
|
+
/** 外部业务是否允许发起查询。 */
|
|
181
|
+
enabled?: boolean;
|
|
182
|
+
/** 判断列是否出现在列设置面板中。 */
|
|
183
|
+
getColumnVisible?: (column: TableColumn<TableDataWithIndex<T>>) => boolean;
|
|
184
|
+
/** 是否首次挂载后立即请求。 */
|
|
185
|
+
immediate?: boolean;
|
|
186
|
+
/** 是否读取并同步路由查询参数。 */
|
|
187
|
+
isChangeURL?: boolean;
|
|
188
|
+
/** 是否使用移动端简洁分页。 */
|
|
189
|
+
isMobile?: boolean;
|
|
190
|
+
/** 表格分页、筛选、排序变化回调。 */
|
|
191
|
+
onChange?: (...args: TableOnChange<TableDataWithIndex<T>>) => Partial<Params> | void;
|
|
192
|
+
/** 查询完成后的业务回调。 */
|
|
193
|
+
onFetched?: (data: PaginationData<TableDataWithIndex<T>>) => Promise<void> | void;
|
|
194
|
+
/** 查询参数变化时的外部路由同步回调。 */
|
|
195
|
+
onSearchParamsChange?: (params: Partial<Params>) => void;
|
|
196
|
+
/** 分页配置;传 false 可关闭分页。 */
|
|
197
|
+
pagination?: false | TablePaginationConfig;
|
|
198
|
+
/** 根据当前查询参数创建 React Query 查询。 */
|
|
199
|
+
queryHook: TableQueryHook<Params, Response>;
|
|
200
|
+
/** 透传给 React Query 的附加配置。 */
|
|
201
|
+
queryOptions?: TableQueryOptions<Response, T>;
|
|
202
|
+
/** 当前路由查询字符串,用于初始化查询参数。 */
|
|
203
|
+
routeSearch?: string;
|
|
204
|
+
/** Ant Design 表格行 key。 */
|
|
205
|
+
rowKey?: TableProps<TableDataWithIndex<T>>['rowKey'];
|
|
206
|
+
/** 是否展示总数。 */
|
|
207
|
+
showTotal?: boolean;
|
|
208
|
+
/** 把接口响应转换成标准分页数据。 */
|
|
209
|
+
transformer?: (response: Response) => PaginationData<T>;
|
|
210
|
+
/** 接口请求前的参数转换。 */
|
|
211
|
+
transformParams?: (params: Params) => Params;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** 自定义表格 Props。 */
|
|
215
|
+
export type CustomTableProps<T> = Omit<TableProps<TableDataWithIndex<T>>, 'loading'> & {
|
|
216
|
+
/** 当前表格是否展示加载状态。 */
|
|
217
|
+
loading: boolean;
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
/** 表格搜索 Props。 */
|
|
221
|
+
export interface TableSearchProps<T = any> {
|
|
222
|
+
/** Ant Design 表单实例。 */
|
|
223
|
+
form: FormInstance<T>;
|
|
224
|
+
/** 重置查询表单。 */
|
|
225
|
+
reset: () => void;
|
|
226
|
+
/** 提交查询表单。 */
|
|
227
|
+
search: (isResetCurrent?: boolean) => Promise<void>;
|
|
228
|
+
/** 当前已提交的查询参数。 */
|
|
229
|
+
searchParams: T;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** 通用弹窗操作 Props。 */
|
|
233
|
+
export interface GeneralPopupOperationProps<T extends TableData = TableData> {
|
|
234
|
+
/** Ant Design 表单实例。 */
|
|
235
|
+
form: FormInstance<T>;
|
|
236
|
+
/** 提交弹窗表单。 */
|
|
237
|
+
handleSubmit: () => Promise<void>;
|
|
238
|
+
/** 关闭弹窗。 */
|
|
239
|
+
onClose: () => void;
|
|
240
|
+
/** 弹窗是否打开。 */
|
|
241
|
+
open: boolean;
|
|
242
|
+
/** 当前操作类型。 */
|
|
243
|
+
operateType: TableOperateType;
|
|
244
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { useBoolean } from 'ahooks';
|
|
2
|
+
import { Form, message } from 'antd';
|
|
3
|
+
import type { TableProps } from 'antd';
|
|
4
|
+
import { useState } from 'react';
|
|
5
|
+
import type { Key } from 'react';
|
|
6
|
+
import { useTranslation } from 'react-i18next';
|
|
7
|
+
|
|
8
|
+
import type { TableData, TableOperateType } from './types';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 表格操作Hook
|
|
12
|
+
*
|
|
13
|
+
* 提供表格常用操作功能: - 添加/编辑抽屉管理 - 表格行选择 - 删除操作
|
|
14
|
+
*/
|
|
15
|
+
export function useTableOperate<T extends TableData = TableData>(
|
|
16
|
+
data: T[],
|
|
17
|
+
getData: (isResetCurrent?: boolean) => Promise<void>,
|
|
18
|
+
executeResActions?: (res: T, operateType: TableOperateType) => void | Promise<void>
|
|
19
|
+
) {
|
|
20
|
+
const { t } = useTranslation();
|
|
21
|
+
|
|
22
|
+
// 抽屉可见性状态
|
|
23
|
+
const [drawerVisible, { setFalse: closeDrawer, setTrue: openDrawer }] = useBoolean();
|
|
24
|
+
|
|
25
|
+
// 操作类型:添加或编辑
|
|
26
|
+
const [operateType, setOperateType] = useState<TableOperateType>('add');
|
|
27
|
+
|
|
28
|
+
// 表单实例
|
|
29
|
+
const [form] = Form.useForm<T>();
|
|
30
|
+
|
|
31
|
+
/** 正在编辑的数据 */
|
|
32
|
+
const [editingData, setEditingData] = useState<T>();
|
|
33
|
+
|
|
34
|
+
/** 处理添加操作 */
|
|
35
|
+
function handleAdd() {
|
|
36
|
+
setOperateType('add');
|
|
37
|
+
setEditingData(undefined);
|
|
38
|
+
form.resetFields();
|
|
39
|
+
openDrawer();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 处理编辑操作
|
|
44
|
+
*
|
|
45
|
+
* @param idOrData - 数据ID或完整数据对象
|
|
46
|
+
*/
|
|
47
|
+
function handleEdit(idOrData: T['id'] | T) {
|
|
48
|
+
if (typeof idOrData === 'object') {
|
|
49
|
+
form.setFieldsValue(idOrData);
|
|
50
|
+
setEditingData(idOrData);
|
|
51
|
+
} else {
|
|
52
|
+
const findItem = data.find(item => item.id === idOrData);
|
|
53
|
+
if (findItem) {
|
|
54
|
+
form.setFieldsValue(findItem);
|
|
55
|
+
setEditingData(findItem);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
setOperateType('edit');
|
|
60
|
+
openDrawer();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** 选中的行keys */
|
|
64
|
+
const [checkedRowKeys, setCheckedRowKeys] = useState<Key[]>([]);
|
|
65
|
+
|
|
66
|
+
/** 行选择变化处理 */
|
|
67
|
+
function onSelectChange(keys: Key[]) {
|
|
68
|
+
setCheckedRowKeys(keys);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 行选择配置 */
|
|
72
|
+
const rowSelection: TableProps<T>['rowSelection'] = {
|
|
73
|
+
columnWidth: 48,
|
|
74
|
+
fixed: true,
|
|
75
|
+
onChange: onSelectChange,
|
|
76
|
+
selectedRowKeys: checkedRowKeys,
|
|
77
|
+
type: 'checkbox'
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/** 关闭抽屉 */
|
|
81
|
+
function onClose() {
|
|
82
|
+
closeDrawer();
|
|
83
|
+
form.resetFields();
|
|
84
|
+
setEditingData(undefined);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** 批量删除完成后的回调 */
|
|
88
|
+
async function onBatchDeleted() {
|
|
89
|
+
message.success(t('common.deleteSuccess'));
|
|
90
|
+
setCheckedRowKeys([]);
|
|
91
|
+
await getData(false);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** 单个删除完成后的回调 */
|
|
95
|
+
async function onDeleted() {
|
|
96
|
+
message.success(t('common.deleteSuccess'));
|
|
97
|
+
await getData(false);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** 提交表单 */
|
|
101
|
+
async function handleSubmit() {
|
|
102
|
+
const res = await form.validateFields();
|
|
103
|
+
|
|
104
|
+
if (executeResActions) {
|
|
105
|
+
// 执行业务逻辑
|
|
106
|
+
await executeResActions(res, operateType);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
message.success(t('common.updateSuccess'));
|
|
110
|
+
|
|
111
|
+
onClose();
|
|
112
|
+
await getData();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
checkedRowKeys,
|
|
117
|
+
closeDrawer,
|
|
118
|
+
drawerVisible,
|
|
119
|
+
editingData,
|
|
120
|
+
generalPopupOperation: {
|
|
121
|
+
form,
|
|
122
|
+
handleSubmit,
|
|
123
|
+
onClose,
|
|
124
|
+
open: drawerVisible,
|
|
125
|
+
operateType
|
|
126
|
+
},
|
|
127
|
+
handleAdd,
|
|
128
|
+
handleEdit,
|
|
129
|
+
onBatchDeleted,
|
|
130
|
+
onDeleted,
|
|
131
|
+
onSelectChange,
|
|
132
|
+
openDrawer,
|
|
133
|
+
operateType,
|
|
134
|
+
rowSelection
|
|
135
|
+
};
|
|
136
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { useSize } from 'ahooks';
|
|
2
|
+
import { useRef } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 表格滚动配置Hook
|
|
6
|
+
*
|
|
7
|
+
* 自动计算表格滚动区域的宽度和高度
|
|
8
|
+
*
|
|
9
|
+
* @param scrollX - 表格最小宽度,默认702
|
|
10
|
+
* @returns 滚动配置和容器ref
|
|
11
|
+
*/
|
|
12
|
+
export function useTableScroll(scrollX: number = 702) {
|
|
13
|
+
const tableWrapperRef = useRef<HTMLDivElement>(null);
|
|
14
|
+
|
|
15
|
+
const size = useSize(tableWrapperRef);
|
|
16
|
+
|
|
17
|
+
/** 获取表格滚动的Y轴高度 */
|
|
18
|
+
function getTableScrollY() {
|
|
19
|
+
const height = size?.height;
|
|
20
|
+
|
|
21
|
+
if (!height) return undefined;
|
|
22
|
+
|
|
23
|
+
// 减去表格头部、分页等组件的高度
|
|
24
|
+
return height - 160;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const scrollConfig = {
|
|
28
|
+
x: scrollX,
|
|
29
|
+
y: getTableScrollY()
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
scrollConfig,
|
|
34
|
+
tableWrapperRef
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 计算表格列的总宽度
|
|
40
|
+
*
|
|
41
|
+
* @param columns - 表格列配置
|
|
42
|
+
* @param minWidth - 列的最小宽度,默认120
|
|
43
|
+
* @returns 总宽度
|
|
44
|
+
*/
|
|
45
|
+
export function getTableScrollX(columns: any[], minWidth: number = 120): number {
|
|
46
|
+
return columns.reduce((acc, column) => {
|
|
47
|
+
return acc + Number(column.width ?? column.minWidth ?? minWidth);
|
|
48
|
+
}, 0);
|
|
49
|
+
}
|