@qlover/create-app 0.7.14 → 0.8.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/CHANGELOG.md +27 -0
- package/dist/configs/_common/.gitignore.template +6 -0
- package/dist/configs/_common/.prettierignore +17 -5
- package/dist/configs/_common/.vscode/settings.json +6 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/templates/next-app/.env.template +1 -1
- package/dist/templates/next-app/README.en.md +130 -0
- package/dist/templates/next-app/README.md +114 -20
- package/dist/templates/next-app/config/Identifier/api.ts +5 -5
- package/dist/templates/next-app/config/Identifier/common/admint.table.ts +69 -0
- package/dist/templates/next-app/config/Identifier/common/common.ts +76 -0
- package/dist/templates/next-app/config/Identifier/common/index.ts +3 -0
- package/dist/templates/next-app/config/Identifier/{validator.ts → common/validators.ts} +5 -5
- package/dist/templates/next-app/config/Identifier/index.ts +2 -12
- package/dist/templates/next-app/config/Identifier/pages/index.ts +6 -0
- package/dist/templates/next-app/config/Identifier/pages/page.admin.home.ts +27 -0
- package/dist/templates/next-app/config/Identifier/pages/page.admin.locales.ts +266 -0
- package/dist/templates/next-app/config/Identifier/pages/page.admin.user.ts +293 -0
- package/dist/templates/{react-app/config/Identifier → next-app/config/Identifier/pages}/page.home.ts +15 -22
- package/dist/templates/next-app/config/Identifier/{page.login.ts → pages/page.login.ts} +28 -34
- package/dist/templates/next-app/config/Identifier/{page.register.ts → pages/page.register.ts} +30 -29
- package/dist/templates/next-app/config/adminNavs.ts +19 -0
- package/dist/templates/next-app/config/common.ts +22 -13
- package/dist/templates/next-app/config/i18n/HomeI18n.ts +5 -5
- package/dist/templates/next-app/config/i18n/admin18n.ts +61 -19
- package/dist/templates/next-app/config/i18n/i18nConfig.ts +2 -0
- package/dist/templates/next-app/config/i18n/i18nKeyScheam.ts +36 -0
- package/dist/templates/next-app/config/i18n/loginI18n.ts +22 -22
- package/dist/templates/next-app/config/i18n/register18n.ts +23 -24
- package/dist/templates/next-app/docs/en/api.md +387 -0
- package/dist/templates/next-app/docs/en/component.md +544 -0
- package/dist/templates/next-app/docs/en/database.md +496 -0
- package/dist/templates/next-app/docs/en/development-guide.md +727 -0
- package/dist/templates/next-app/docs/en/env.md +563 -0
- package/dist/templates/next-app/docs/en/i18n.md +287 -0
- package/dist/templates/next-app/docs/en/index.md +165 -0
- package/dist/templates/next-app/docs/en/page.md +457 -0
- package/dist/templates/next-app/docs/en/project-structure.md +176 -0
- package/dist/templates/next-app/docs/en/router.md +427 -0
- package/dist/templates/next-app/docs/en/theme.md +532 -0
- package/dist/templates/next-app/docs/en/validator.md +478 -0
- package/dist/templates/next-app/docs/zh/api.md +387 -0
- package/dist/templates/next-app/docs/zh/component.md +544 -0
- package/dist/templates/next-app/docs/zh/database.md +496 -0
- package/dist/templates/next-app/docs/zh/development-guide.md +727 -0
- package/dist/templates/next-app/docs/zh/env.md +563 -0
- package/dist/templates/next-app/docs/zh/i18n.md +287 -0
- package/dist/templates/next-app/docs/zh/index.md +165 -0
- package/dist/templates/next-app/docs/zh/page.md +457 -0
- package/dist/templates/next-app/docs/zh/project-structure.md +176 -0
- package/dist/templates/next-app/docs/zh/router.md +427 -0
- package/dist/templates/next-app/docs/zh/theme.md +532 -0
- package/dist/templates/next-app/docs/zh/validator.md +476 -0
- package/dist/templates/next-app/make/generateLocales.ts +19 -12
- package/dist/templates/next-app/migrations/schema/LocalesSchema.ts +15 -0
- package/dist/templates/next-app/migrations/sql/1694244000000.sql +11 -0
- package/dist/templates/next-app/package.json +7 -3
- package/dist/templates/next-app/public/locales/en.json +172 -207
- package/dist/templates/next-app/public/locales/zh.json +172 -207
- package/dist/templates/next-app/src/app/[locale]/admin/locales/page.tsx +153 -0
- package/dist/templates/next-app/src/app/[locale]/admin/users/page.tsx +48 -50
- package/dist/templates/next-app/src/app/[locale]/login/LoginForm.tsx +2 -2
- package/dist/templates/next-app/src/app/api/admin/locales/create/route.ts +34 -0
- package/dist/templates/next-app/src/app/api/admin/locales/import/route.ts +40 -0
- package/dist/templates/next-app/src/app/api/admin/locales/route.ts +42 -0
- package/dist/templates/next-app/src/app/api/admin/locales/update/route.ts +32 -0
- package/dist/templates/next-app/src/app/api/locales/json/route.ts +44 -0
- package/dist/templates/next-app/src/base/cases/AdminPageManager.ts +1 -13
- package/dist/templates/next-app/src/base/cases/Datetime.ts +18 -0
- package/dist/templates/next-app/src/base/cases/DialogErrorPlugin.ts +12 -6
- package/dist/templates/next-app/src/base/cases/ResourceState.ts +17 -0
- package/dist/templates/next-app/src/base/cases/TranslateI18nInterface.ts +25 -0
- package/dist/templates/next-app/src/base/cases/ZodColumnBuilder.ts +200 -0
- package/dist/templates/next-app/src/base/port/ZodBuilderInterface.ts +8 -0
- package/dist/templates/next-app/src/base/services/AdminLocalesService.ts +20 -0
- package/dist/templates/next-app/src/base/services/AdminPageEvent.ts +26 -0
- package/dist/templates/next-app/src/base/services/AdminPageScheduler.ts +42 -0
- package/dist/templates/next-app/src/base/services/ResourceService.ts +122 -0
- package/dist/templates/next-app/src/base/services/adminApi/AdminLocalesApi.ts +104 -0
- package/dist/templates/next-app/src/base/services/adminApi/AdminUserApi.ts +38 -5
- package/dist/templates/next-app/src/base/services/appApi/AppApiPlugin.ts +1 -1
- package/dist/templates/next-app/src/i18n/request.ts +30 -1
- package/dist/templates/next-app/src/server/PageParams.ts +2 -10
- package/dist/templates/next-app/src/server/port/DBBridgeInterface.ts +5 -0
- package/dist/templates/next-app/src/server/port/DBTableInterface.ts +2 -0
- package/dist/templates/next-app/src/server/port/LocalesRepositoryInterface.ts +43 -0
- package/dist/templates/next-app/src/server/repositorys/LocalesRepository.ts +197 -0
- package/dist/templates/next-app/src/server/services/ApiLocaleService.ts +122 -0
- package/dist/templates/next-app/src/server/sqlBridges/SupabaseBridge.ts +60 -11
- package/dist/templates/next-app/src/server/validators/ExtendedExecutorError.ts +6 -0
- package/dist/templates/next-app/src/server/validators/LocalesValidator.ts +131 -0
- package/dist/templates/next-app/src/server/validators/LoginValidator.ts +2 -5
- package/dist/templates/next-app/src/server/validators/PaginationValidator.ts +32 -16
- package/dist/templates/next-app/src/styles/css/antd-themes/pagination/_default.css +2 -1
- package/dist/templates/next-app/src/styles/css/antd-themes/pagination/dark.css +28 -29
- package/dist/templates/next-app/src/styles/css/antd-themes/pagination/pink.css +2 -1
- package/dist/templates/next-app/src/uikit/components/AdminLayout.tsx +17 -3
- package/dist/templates/next-app/src/uikit/components/BaseHeader.tsx +5 -4
- package/dist/templates/next-app/src/uikit/components/BaseLayout.tsx +5 -4
- package/dist/templates/next-app/src/uikit/components/BootstrapsProvider.tsx +3 -2
- package/dist/templates/next-app/src/uikit/components/ComboProvider.tsx +1 -1
- package/dist/templates/next-app/src/uikit/components/EditableCell.tsx +118 -0
- package/dist/templates/next-app/src/uikit/components/LogoutButton.tsx +5 -6
- package/dist/templates/next-app/src/uikit/components/ThemeSwitcher.tsx +1 -1
- package/dist/templates/next-app/src/uikit/components/With.tsx +2 -2
- package/dist/templates/next-app/src/uikit/components/localesImportButton/LocalesImportButton.tsx +62 -0
- package/dist/templates/next-app/src/uikit/components/localesImportButton/LocalesImportEvent.ts +28 -0
- package/dist/templates/next-app/src/uikit/components/localesImportButton/import.module.css +6 -0
- package/dist/templates/next-app/src/uikit/hook/useI18nInterface.ts +8 -14
- package/dist/templates/next-app/src/uikit/hook/useWarnTranslations.ts +25 -0
- package/dist/templates/react-app/.prettierignore +17 -0
- package/dist/templates/react-app/README.en.md +71 -54
- package/dist/templates/react-app/README.md +35 -18
- package/dist/templates/react-app/__tests__/__mocks__/BootstrapTest.ts +14 -0
- package/dist/templates/react-app/__tests__/__mocks__/MockAppConfit.ts +1 -1
- package/dist/templates/react-app/__tests__/__mocks__/MockDialogHandler.ts +2 -2
- package/dist/templates/react-app/__tests__/__mocks__/MockLogger.ts +1 -1
- package/dist/templates/react-app/__tests__/__mocks__/components/TestApp.tsx +45 -0
- package/dist/templates/react-app/__tests__/__mocks__/components/TestBootstrapsProvider.tsx +34 -0
- package/dist/templates/react-app/__tests__/__mocks__/components/TestRouter.tsx +46 -0
- package/dist/templates/react-app/__tests__/__mocks__/components/index.ts +12 -0
- package/dist/templates/react-app/__tests__/__mocks__/createMockGlobals.ts +1 -2
- package/dist/templates/react-app/__tests__/__mocks__/testIOC/TestIOC.ts +51 -0
- package/dist/templates/react-app/__tests__/__mocks__/testIOC/TestIOCRegister.ts +69 -0
- package/dist/templates/react-app/__tests__/setup/index.ts +1 -51
- package/dist/templates/react-app/__tests__/setup/setupGlobal.ts +51 -0
- package/dist/templates/react-app/__tests__/src/App.structure.test.tsx +115 -0
- package/dist/templates/react-app/__tests__/src/base/cases/AppConfig.test.ts +2 -2
- package/dist/templates/react-app/__tests__/src/base/cases/AppError.test.ts +1 -1
- package/dist/templates/react-app/__tests__/src/base/cases/DialogHandler.test.ts +3 -5
- package/dist/templates/react-app/__tests__/src/base/cases/I18nKeyErrorPlugin.test.ts +13 -2
- package/dist/templates/react-app/__tests__/src/base/cases/InversifyContainer.test.ts +1 -1
- package/dist/templates/react-app/__tests__/src/base/cases/PublicAssetsPath.test.ts +1 -1
- package/dist/templates/react-app/__tests__/src/base/cases/RequestLogger.test.ts +5 -5
- package/dist/templates/react-app/__tests__/src/base/cases/RequestStatusCatcher.test.ts +1 -2
- package/dist/templates/react-app/__tests__/src/base/cases/RouterLoader.test.ts +25 -15
- package/dist/templates/react-app/__tests__/src/base/services/I18nService.test.ts +29 -15
- package/dist/templates/react-app/__tests__/src/core/IOC.test.ts +19 -9
- package/dist/templates/react-app/__tests__/src/core/bootstraps/BootstrapClient.test.ts +153 -0
- package/dist/templates/react-app/__tests__/src/core/bootstraps/BootstrapsApp.test.ts +9 -7
- package/dist/templates/react-app/__tests__/src/main.integration.test.tsx +4 -5
- package/dist/templates/react-app/__tests__/src/main.test.tsx +4 -4
- package/dist/templates/react-app/__tests__/src/uikit/components/BaseHeader.test.tsx +68 -59
- package/dist/templates/react-app/config/IOCIdentifier.ts +8 -8
- package/dist/templates/react-app/config/Identifier/{common.error.ts → common/common.error.ts} +5 -5
- package/dist/templates/react-app/config/Identifier/{common.ts → common/common.ts} +9 -9
- package/dist/templates/react-app/config/Identifier/common/index.ts +2 -0
- package/dist/templates/react-app/config/Identifier/index.ts +1 -9
- package/dist/templates/react-app/config/Identifier/pages/index.ts +8 -0
- package/dist/templates/react-app/config/Identifier/{page.about.ts → pages/page.about.ts} +34 -26
- package/dist/templates/react-app/config/Identifier/{page.executor.ts → pages/page.executor.ts} +47 -39
- package/dist/templates/{next-app/config/Identifier → react-app/config/Identifier/pages}/page.home.ts +24 -23
- package/dist/templates/react-app/config/Identifier/pages/page.identifiter.ts +102 -0
- package/dist/templates/react-app/config/Identifier/{page.jsonStorage.ts → pages/page.jsonStorage.ts} +18 -11
- package/dist/templates/react-app/config/Identifier/{page.login.ts → pages/page.login.ts} +37 -27
- package/dist/templates/react-app/config/Identifier/{page.register.ts → pages/page.register.ts} +37 -25
- package/dist/templates/react-app/config/Identifier/{page.request.ts → pages/page.request.ts} +34 -44
- package/dist/templates/react-app/config/app.router.ts +66 -69
- package/dist/templates/react-app/config/i18n/PageI18nInterface.ts +51 -0
- package/dist/templates/react-app/config/i18n/aboutI18n.ts +42 -0
- package/dist/templates/react-app/config/i18n/executorI18n.ts +51 -0
- package/dist/templates/react-app/config/i18n/homeI18n.ts +24 -0
- package/dist/templates/react-app/config/i18n/i18nConfig.ts +30 -0
- package/dist/templates/react-app/config/i18n/identifiter18n.ts +30 -0
- package/dist/templates/react-app/config/i18n/jsonStorage18n.ts +27 -0
- package/dist/templates/react-app/config/i18n/login18n.ts +42 -0
- package/dist/templates/react-app/config/i18n/notFoundI18n.ts +34 -0
- package/dist/templates/react-app/config/i18n/register18n.ts +40 -0
- package/dist/templates/react-app/config/i18n/request18n.ts +41 -0
- package/dist/templates/react-app/config/theme.ts +14 -4
- package/dist/templates/react-app/docs/en/bootstrap.md +1670 -341
- package/dist/templates/react-app/docs/en/development-guide.md +1021 -345
- package/dist/templates/react-app/docs/en/env.md +1132 -278
- package/dist/templates/react-app/docs/en/i18n.md +858 -147
- package/dist/templates/react-app/docs/en/index.md +733 -104
- package/dist/templates/react-app/docs/en/ioc.md +1228 -287
- package/dist/templates/react-app/docs/en/playwright/e2e-tests.md +321 -0
- package/dist/templates/react-app/docs/en/playwright/index.md +19 -0
- package/dist/templates/react-app/docs/en/playwright/installation-summary.md +332 -0
- package/dist/templates/react-app/docs/en/playwright/overview.md +222 -0
- package/dist/templates/react-app/docs/en/playwright/quickstart.md +325 -0
- package/dist/templates/react-app/docs/en/playwright/reorganization-notes.md +340 -0
- package/dist/templates/react-app/docs/en/playwright/setup-complete.md +290 -0
- package/dist/templates/react-app/docs/en/playwright/testing-guide.md +565 -0
- package/dist/templates/react-app/docs/en/store.md +1194 -184
- package/dist/templates/react-app/docs/en/why-no-globals.md +797 -0
- package/dist/templates/react-app/docs/zh/bootstrap.md +1670 -341
- package/dist/templates/react-app/docs/zh/development-guide.md +1021 -345
- package/dist/templates/react-app/docs/zh/env.md +1132 -275
- package/dist/templates/react-app/docs/zh/i18n.md +858 -147
- package/dist/templates/react-app/docs/zh/index.md +717 -104
- package/dist/templates/react-app/docs/zh/ioc.md +1229 -287
- package/dist/templates/react-app/docs/zh/playwright/e2e-tests.md +321 -0
- package/dist/templates/react-app/docs/zh/playwright/index.md +19 -0
- package/dist/templates/react-app/docs/zh/playwright/installation-summary.md +332 -0
- package/dist/templates/react-app/docs/zh/playwright/overview.md +222 -0
- package/dist/templates/react-app/docs/zh/playwright/quickstart.md +325 -0
- package/dist/templates/react-app/docs/zh/playwright/reorganization-notes.md +340 -0
- package/dist/templates/react-app/docs/zh/playwright/setup-complete.md +290 -0
- package/dist/templates/react-app/docs/zh/playwright/testing-guide.md +565 -0
- package/dist/templates/react-app/docs/zh/store.md +1192 -184
- package/dist/templates/react-app/docs/zh/why-no-globals.md +797 -0
- package/dist/templates/react-app/e2e/App.spec.ts +319 -0
- package/dist/templates/react-app/e2e/fixtures/base.fixture.ts +40 -0
- package/dist/templates/react-app/e2e/main.spec.ts +20 -0
- package/dist/templates/react-app/e2e/utils/test-helpers.ts +19 -0
- package/dist/templates/react-app/eslint.config.mjs +247 -0
- package/dist/templates/react-app/makes/eslint-utils.mjs +195 -0
- package/dist/templates/react-app/makes/generateTs2LocalesOptions.ts +26 -0
- package/dist/templates/react-app/package.json +31 -3
- package/dist/templates/react-app/playwright.config.ts +79 -0
- package/dist/templates/react-app/public/locales/en/common.json +190 -179
- package/dist/templates/react-app/public/locales/zh/common.json +190 -179
- package/dist/templates/react-app/src/App.tsx +15 -42
- package/dist/templates/react-app/src/base/apis/AiApi.ts +5 -5
- package/dist/templates/react-app/src/base/apis/feApi/FeApi.ts +1 -1
- package/dist/templates/react-app/src/base/apis/feApi/FeApiAdapter.ts +1 -1
- package/dist/templates/react-app/src/base/apis/feApi/FeApiBootstarp.ts +8 -8
- package/dist/templates/react-app/src/base/apis/feApi/FeApiType.ts +1 -1
- package/dist/templates/react-app/src/base/apis/userApi/UserApi.ts +6 -6
- package/dist/templates/react-app/src/base/apis/userApi/UserApiAdapter.ts +1 -1
- package/dist/templates/react-app/src/base/apis/userApi/UserApiBootstarp.ts +12 -14
- package/dist/templates/react-app/src/base/apis/userApi/UserApiType.ts +1 -1
- package/dist/templates/react-app/src/base/cases/DialogHandler.ts +5 -2
- package/dist/templates/react-app/src/base/cases/I18nKeyErrorPlugin.ts +3 -3
- package/dist/templates/react-app/src/base/cases/InversifyContainer.ts +3 -3
- package/dist/templates/react-app/src/base/cases/RequestLanguages.ts +2 -2
- package/dist/templates/react-app/src/base/cases/RequestLogger.ts +4 -4
- package/dist/templates/react-app/src/base/cases/RequestStatusCatcher.ts +1 -1
- package/dist/templates/react-app/src/base/cases/ResourceState.ts +23 -0
- package/dist/templates/react-app/src/base/cases/RouterLoader.ts +4 -4
- package/dist/templates/react-app/src/base/cases/TranslateI18nInterface.ts +26 -0
- package/dist/templates/react-app/src/base/port/ExecutorPageBridgeInterface.ts +2 -3
- package/dist/templates/react-app/src/base/port/I18nServiceInterface.ts +1 -1
- package/dist/templates/react-app/src/base/port/IOCInterface.ts +36 -0
- package/dist/templates/react-app/src/base/port/JSONStoragePageBridgeInterface.ts +2 -1
- package/dist/templates/react-app/src/base/port/ProcesserExecutorInterface.ts +1 -1
- package/dist/templates/react-app/src/base/port/RequestPageBridgeInterface.ts +2 -2
- package/dist/templates/react-app/src/base/port/RouteServiceInterface.ts +9 -5
- package/dist/templates/react-app/src/base/port/UserServiceInterface.ts +1 -1
- package/dist/templates/react-app/src/base/services/I18nService.ts +29 -29
- package/dist/templates/react-app/src/base/services/IdentifierService.ts +143 -0
- package/dist/templates/react-app/src/base/services/ProcesserExecutor.ts +3 -3
- package/dist/templates/react-app/src/base/services/RouteService.ts +27 -8
- package/dist/templates/react-app/src/base/services/UserService.ts +8 -8
- package/dist/templates/react-app/src/base/types/Page.ts +14 -2
- package/dist/templates/react-app/src/base/types/global.d.ts +1 -1
- package/dist/templates/react-app/src/core/IOC.ts +5 -46
- package/dist/templates/react-app/src/core/bootstraps/{BootstrapApp.ts → BootstrapClient.ts} +44 -17
- package/dist/templates/react-app/src/core/bootstraps/BootstrapsRegistry.ts +14 -7
- package/dist/templates/react-app/src/core/bootstraps/IocIdentifierTest.ts +1 -1
- package/dist/templates/react-app/src/core/bootstraps/PrintBootstrap.ts +1 -1
- package/dist/templates/react-app/src/core/clientIoc/ClientIOC.ts +40 -0
- package/dist/templates/react-app/src/core/{IocRegisterImpl.ts → clientIoc/ClientIOCRegister.ts} +35 -24
- package/dist/templates/react-app/src/core/globals.ts +9 -9
- package/dist/templates/react-app/src/main.tsx +4 -4
- package/dist/templates/react-app/src/pages/404.tsx +6 -3
- package/dist/templates/react-app/src/pages/500.tsx +5 -2
- package/dist/templates/react-app/src/pages/NoRouteFound.tsx +5 -0
- package/dist/templates/react-app/src/pages/auth/Layout.tsx +9 -6
- package/dist/templates/react-app/src/pages/auth/LoginPage.tsx +46 -56
- package/dist/templates/react-app/src/pages/auth/RegisterPage.tsx +46 -58
- package/dist/templates/react-app/src/pages/base/AboutPage.tsx +35 -40
- package/dist/templates/react-app/src/pages/base/ExecutorPage.tsx +51 -51
- package/dist/templates/react-app/src/pages/base/HomePage.tsx +14 -15
- package/dist/templates/react-app/src/pages/base/IdentifierPage.tsx +70 -11
- package/dist/templates/react-app/src/pages/base/JSONStoragePage.tsx +24 -25
- package/dist/templates/react-app/src/pages/base/Layout.tsx +2 -2
- package/dist/templates/react-app/src/pages/base/RedirectPathname.tsx +3 -2
- package/dist/templates/react-app/src/pages/base/RequestPage.tsx +41 -59
- package/dist/templates/react-app/src/styles/css/antd-themes/{_default.css → _common/_default.css} +85 -0
- package/dist/templates/react-app/src/styles/css/antd-themes/{dark.css → _common/dark.css} +99 -0
- package/dist/templates/react-app/src/styles/css/antd-themes/_common/index.css +3 -0
- package/dist/templates/react-app/src/styles/css/antd-themes/{pink.css → _common/pink.css} +86 -0
- package/dist/templates/react-app/src/styles/css/antd-themes/index.css +4 -3
- package/dist/templates/react-app/src/styles/css/antd-themes/menu/_default.css +108 -0
- package/dist/templates/react-app/src/styles/css/antd-themes/menu/dark.css +67 -0
- package/dist/templates/react-app/src/styles/css/antd-themes/menu/index.css +3 -0
- package/dist/templates/react-app/src/styles/css/antd-themes/menu/pink.css +67 -0
- package/dist/templates/react-app/src/styles/css/antd-themes/pagination/_default.css +34 -0
- package/dist/templates/react-app/src/styles/css/antd-themes/pagination/dark.css +31 -0
- package/dist/templates/react-app/src/styles/css/antd-themes/pagination/index.css +3 -0
- package/dist/templates/react-app/src/styles/css/antd-themes/pagination/pink.css +36 -0
- package/dist/templates/react-app/src/styles/css/antd-themes/table/_default.css +44 -0
- package/dist/templates/react-app/src/styles/css/antd-themes/table/dark.css +43 -0
- package/dist/templates/react-app/src/styles/css/antd-themes/table/index.css +3 -0
- package/dist/templates/react-app/src/styles/css/antd-themes/table/pink.css +43 -0
- package/dist/templates/react-app/src/styles/css/page.css +4 -3
- package/dist/templates/react-app/src/styles/css/themes/_default.css +1 -0
- package/dist/templates/react-app/src/styles/css/themes/dark.css +1 -0
- package/dist/templates/react-app/src/styles/css/themes/pink.css +1 -0
- package/dist/templates/react-app/src/styles/css/zIndex.css +1 -1
- package/dist/templates/react-app/src/uikit/bridges/ExecutorPageBridge.ts +3 -3
- package/dist/templates/react-app/src/uikit/bridges/JSONStoragePageBridge.ts +2 -2
- package/dist/templates/react-app/src/uikit/bridges/NavigateBridge.ts +1 -1
- package/dist/templates/react-app/src/uikit/bridges/RequestPageBridge.ts +3 -3
- package/dist/templates/react-app/src/uikit/components/AppRouterProvider.tsx +35 -0
- package/dist/templates/react-app/src/uikit/components/BaseHeader.tsx +15 -11
- package/dist/templates/react-app/src/uikit/components/BaseRouteProvider.tsx +14 -11
- package/dist/templates/react-app/src/uikit/components/BaseRouteSeo.tsx +18 -0
- package/dist/templates/react-app/src/uikit/components/BootstrapsProvider.tsx +13 -0
- package/dist/templates/react-app/src/uikit/components/ClientSeo.tsx +62 -0
- package/dist/templates/react-app/src/uikit/components/ComboProvider.tsx +38 -0
- package/dist/templates/react-app/src/uikit/components/LanguageSwitcher.tsx +48 -27
- package/dist/templates/react-app/src/uikit/components/Loading.tsx +4 -2
- package/dist/templates/react-app/src/uikit/components/LocaleLink.tsx +4 -5
- package/dist/templates/react-app/src/uikit/components/LogoutButton.tsx +34 -11
- package/dist/templates/react-app/src/uikit/components/ProcessExecutorProvider.tsx +9 -5
- package/dist/templates/react-app/src/uikit/components/RouterRenderComponent.tsx +6 -3
- package/dist/templates/react-app/src/uikit/components/ThemeSwitcher.tsx +97 -40
- package/dist/templates/react-app/src/uikit/components/UserAuthProvider.tsx +5 -5
- package/dist/templates/react-app/src/uikit/components/With.tsx +17 -0
- package/dist/templates/react-app/src/uikit/contexts/BaseRouteContext.ts +17 -11
- package/dist/templates/react-app/src/uikit/contexts/IOCContext.ts +13 -0
- package/dist/templates/react-app/src/uikit/hooks/useAppTranslation.ts +26 -0
- package/dist/templates/react-app/src/uikit/hooks/useI18nGuard.ts +8 -11
- package/dist/templates/react-app/src/uikit/hooks/useI18nInterface.ts +25 -0
- package/dist/templates/react-app/src/uikit/hooks/useIOC.ts +35 -0
- package/dist/templates/react-app/src/uikit/hooks/useNavigateBridge.ts +3 -3
- package/dist/templates/react-app/src/uikit/hooks/useStrictEffect.ts +0 -1
- package/dist/templates/react-app/tsconfig.e2e.json +21 -0
- package/dist/templates/react-app/tsconfig.json +8 -1
- package/dist/templates/react-app/tsconfig.node.json +1 -1
- package/dist/templates/react-app/tsconfig.test.json +3 -1
- package/dist/templates/react-app/vite.config.ts +50 -34
- package/package.json +2 -1
- package/dist/configs/react-app/eslint.config.js +0 -94
- package/dist/templates/next-app/config/Identifier/common.error.ts +0 -41
- package/dist/templates/next-app/config/Identifier/common.ts +0 -69
- package/dist/templates/next-app/config/Identifier/page.about.ts +0 -181
- package/dist/templates/next-app/config/Identifier/page.admin.ts +0 -48
- package/dist/templates/next-app/config/Identifier/page.executor.ts +0 -272
- package/dist/templates/next-app/config/Identifier/page.identifiter.ts +0 -39
- package/dist/templates/next-app/config/Identifier/page.jsonStorage.ts +0 -72
- package/dist/templates/next-app/config/Identifier/page.request.ts +0 -182
- package/dist/templates/next-app/docs/env.md +0 -94
- package/dist/templates/next-app/src/base/cases/ChatAction.ts +0 -21
- package/dist/templates/next-app/src/base/cases/FocusBarAction.ts +0 -36
- package/dist/templates/next-app/src/base/cases/RequestState.ts +0 -20
- package/dist/templates/next-app/src/base/port/AdminPageInterface.ts +0 -85
- package/dist/templates/next-app/src/base/port/AsyncStateInterface.ts +0 -7
- package/dist/templates/next-app/src/base/services/AdminUserService.ts +0 -45
- package/dist/templates/next-app/src/uikit/components/ChatRoot.tsx +0 -17
- package/dist/templates/next-app/src/uikit/components/chat/ChatActionInterface.ts +0 -30
- package/dist/templates/next-app/src/uikit/components/chat/ChatFocusBar.tsx +0 -65
- package/dist/templates/next-app/src/uikit/components/chat/ChatMessages.tsx +0 -59
- package/dist/templates/next-app/src/uikit/components/chat/ChatWrap.tsx +0 -28
- package/dist/templates/next-app/src/uikit/components/chat/FocusBarActionInterface.ts +0 -19
- package/dist/templates/next-app/src/uikit/hook/useMountedClient.ts +0 -17
- package/dist/templates/next-app/src/uikit/hook/useStore.ts +0 -15
- package/dist/templates/react-app/__tests__/__mocks__/I18nService.ts +0 -13
- package/dist/templates/react-app/__tests__/src/App.test.tsx +0 -139
- package/dist/templates/react-app/config/Identifier/page.identifiter.ts +0 -39
- package/dist/templates/react-app/config/i18n.ts +0 -15
- package/dist/templates/react-app/docs/en/project-structure.md +0 -434
- package/dist/templates/react-app/docs/zh/project-structure.md +0 -434
- package/dist/templates/react-app/src/base/cases/RequestState.ts +0 -20
- package/dist/templates/react-app/src/base/port/AsyncStateInterface.ts +0 -7
- package/dist/templates/react-app/src/uikit/hooks/useDocumentTitle.ts +0 -15
- package/dist/templates/react-app/src/uikit/hooks/useStore.ts +0 -15
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
# Next.js 页面开发指南
|
|
2
|
+
|
|
3
|
+
## 目录
|
|
4
|
+
|
|
5
|
+
1. [页面开发概述](#页面开发概述)
|
|
6
|
+
2. [服务端组件详解](#服务端组件详解)
|
|
7
|
+
3. [客户端组件详解](#客户端组件详解)
|
|
8
|
+
4. [数据获取和状态管理](#数据获取和状态管理)
|
|
9
|
+
5. [页面路由和元数据](#页面路由和元数据)
|
|
10
|
+
6. [最佳实践和性能优化](#最佳实践和性能优化)
|
|
11
|
+
|
|
12
|
+
## 页面开发概述
|
|
13
|
+
|
|
14
|
+
### 1. 服务端组件 vs 客户端组件
|
|
15
|
+
|
|
16
|
+
在 Next.js 13+ 中,所有组件默认都是服务端组件(Server Components),除非显式声明为客户端组件。
|
|
17
|
+
|
|
18
|
+
```typescript
|
|
19
|
+
// 服务端组件(默认)
|
|
20
|
+
// page.tsx
|
|
21
|
+
export default function Page() {
|
|
22
|
+
return <div>服务端渲染的内容</div>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// 客户端组件
|
|
26
|
+
// 需要在文件顶部添加 'use client' 指令
|
|
27
|
+
'use client';
|
|
28
|
+
|
|
29
|
+
export function ClientComponent() {
|
|
30
|
+
return <div>客户端渲染的内容</div>;
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### 2. 选择指南
|
|
35
|
+
|
|
36
|
+
**使用服务端组件的场景**:
|
|
37
|
+
|
|
38
|
+
- 需要直接访问后端资源
|
|
39
|
+
- 包含敏感信息(API 密钥、tokens 等)
|
|
40
|
+
- 依赖后端的重量级操作
|
|
41
|
+
- 需要减少客户端 JavaScript 体积
|
|
42
|
+
- 需要 SEO 优化
|
|
43
|
+
- 页面级组件
|
|
44
|
+
- 不需要客户端交互
|
|
45
|
+
- 不需要浏览器 API
|
|
46
|
+
|
|
47
|
+
**使用客户端组件的场景**:
|
|
48
|
+
|
|
49
|
+
- 需要添加交互和事件处理
|
|
50
|
+
- 使用浏览器 API
|
|
51
|
+
- 使用 React hooks
|
|
52
|
+
- 需要维护组件状态
|
|
53
|
+
- 需要使用客户端特有的生命周期
|
|
54
|
+
- 使用依赖浏览器 API 的第三方库
|
|
55
|
+
|
|
56
|
+
## 服务端组件详解
|
|
57
|
+
|
|
58
|
+
### 1. 基本结构
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
// app/[locale]/login/page.tsx
|
|
62
|
+
export default async function LoginPage(props: PageParamsProps) {
|
|
63
|
+
// 1. 参数验证
|
|
64
|
+
if (!props.params) {
|
|
65
|
+
return notFound();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 2. 服务端初始化
|
|
69
|
+
const params = await props.params;
|
|
70
|
+
const pageParams = new PageParams(params);
|
|
71
|
+
const server = new BootstrapServer();
|
|
72
|
+
|
|
73
|
+
// 3. 服务端数据获取和验证
|
|
74
|
+
if (await server.getIOC(ServerAuth).hasAuth()) {
|
|
75
|
+
return redirect({ href: '/', locale: params.locale! });
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// 4. 获取国际化文本
|
|
79
|
+
const tt = await pageParams.getI18nInterface(loginI18n);
|
|
80
|
+
|
|
81
|
+
// 5. 渲染页面
|
|
82
|
+
return (
|
|
83
|
+
<BaseLayout>
|
|
84
|
+
<div>{/* 页面内容 */}</div>
|
|
85
|
+
<ClientComponent /> {/* 嵌入客户端组件 */}
|
|
86
|
+
</BaseLayout>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### 2. 服务端数据获取
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
// 直接在服务端组件中获取数据
|
|
95
|
+
export default async function UsersPage() {
|
|
96
|
+
const server = new BootstrapServer();
|
|
97
|
+
|
|
98
|
+
const result = await server
|
|
99
|
+
.use(new AdminAuthPlugin()) // 使用服务端中间件
|
|
100
|
+
.execNoError(async ({ parameters: { IOC } }) => {
|
|
101
|
+
const userService = IOC(UserService);
|
|
102
|
+
return userService.getUsers();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// 数据直接传递给客户端组件
|
|
106
|
+
return <UserList initialData={result.data} />;
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### 3. 静态生成和动态渲染
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
// 静态页面生成
|
|
114
|
+
export const dynamic = 'force-static'; // 强制静态生成
|
|
115
|
+
export const revalidate = 3600; // 每小时重新生成
|
|
116
|
+
|
|
117
|
+
// 动态页面生成
|
|
118
|
+
export const dynamic = 'force-dynamic'; // 强制动态生成
|
|
119
|
+
|
|
120
|
+
// 生成静态路由参数
|
|
121
|
+
export async function generateStaticParams() {
|
|
122
|
+
return [{ locale: 'en' }, { locale: 'zh' }];
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## 客户端组件详解
|
|
127
|
+
|
|
128
|
+
### 1. 基本结构
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
'use client'; // 声明为客户端组件
|
|
132
|
+
|
|
133
|
+
export function LoginForm(props: { tt: LoginI18nInterface }) {
|
|
134
|
+
// 1. Hooks 使用
|
|
135
|
+
const [loading, setLoading] = useState(false);
|
|
136
|
+
const userService = useIOC(I.UserServiceInterface);
|
|
137
|
+
|
|
138
|
+
// 2. 事件处理
|
|
139
|
+
const handleLogin = async (values: LoginFormData) => {
|
|
140
|
+
try {
|
|
141
|
+
setLoading(true);
|
|
142
|
+
await userService.login(values);
|
|
143
|
+
routerService.gotoHome();
|
|
144
|
+
} catch (error) {
|
|
145
|
+
logger.error(error);
|
|
146
|
+
} finally {
|
|
147
|
+
setLoading(false);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// 3. 渲染 UI
|
|
152
|
+
return (
|
|
153
|
+
<Form onFinish={handleLogin}>
|
|
154
|
+
{/* 表单内容 */}
|
|
155
|
+
</Form>
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### 2. 客户端状态管理
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
'use client';
|
|
164
|
+
|
|
165
|
+
export function UserProfile() {
|
|
166
|
+
// 1. 本地状态
|
|
167
|
+
const [isEditing, setIsEditing] = useState(false);
|
|
168
|
+
|
|
169
|
+
// 2. 服务状态
|
|
170
|
+
const userStore = useIOC(UserStore);
|
|
171
|
+
const user = useStore(userStore, userStore.selector.currentUser);
|
|
172
|
+
|
|
173
|
+
// 3. 表单状态
|
|
174
|
+
const [form] = Form.useForm();
|
|
175
|
+
|
|
176
|
+
// 4. 副作用
|
|
177
|
+
useEffect(() => {
|
|
178
|
+
if (user) {
|
|
179
|
+
form.setFieldsValue(user);
|
|
180
|
+
}
|
|
181
|
+
}, [user, form]);
|
|
182
|
+
|
|
183
|
+
return (
|
|
184
|
+
<div>{/* 组件内容 */}</div>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### 3. 与服务端组件交互
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
// 1. 通过属性接收服务端数据
|
|
193
|
+
interface Props {
|
|
194
|
+
initialData: UserData; // 从服务端获取的初始数据
|
|
195
|
+
tt: I18nInterface; // 从服务端获取的翻译文本
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
'use client';
|
|
199
|
+
export function UserList({ initialData, tt }: Props) {
|
|
200
|
+
const [data, setData] = useState(initialData);
|
|
201
|
+
|
|
202
|
+
// 使用服务端数据初始化客户端状态
|
|
203
|
+
useEffect(() => {
|
|
204
|
+
setData(initialData);
|
|
205
|
+
}, [initialData]);
|
|
206
|
+
|
|
207
|
+
return (
|
|
208
|
+
<div>{/* 组件内容 */}</div>
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## 数据获取和状态管理
|
|
214
|
+
|
|
215
|
+
### 1. 服务端数据获取
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
// 1. 在服务端组件中获取数据
|
|
219
|
+
export default async function DashboardPage() {
|
|
220
|
+
const server = new BootstrapServer();
|
|
221
|
+
|
|
222
|
+
// 并行数据获取
|
|
223
|
+
const [userData, statsData] = await Promise.all([
|
|
224
|
+
server.execNoError(async ({ IOC }) => IOC(UserService).getCurrentUser()),
|
|
225
|
+
server.execNoError(async ({ IOC }) => IOC(StatsService).getStats())
|
|
226
|
+
]);
|
|
227
|
+
|
|
228
|
+
return (
|
|
229
|
+
<Dashboard
|
|
230
|
+
userData={userData}
|
|
231
|
+
statsData={statsData}
|
|
232
|
+
/>
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// 2. 使用服务端 action
|
|
237
|
+
export async function fetchUserData(userId: string) {
|
|
238
|
+
'use server'; // 声明为服务端 action
|
|
239
|
+
|
|
240
|
+
const server = new BootstrapServer();
|
|
241
|
+
return server.execNoError(async ({ IOC }) => {
|
|
242
|
+
return IOC(UserService).getUserById(userId);
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### 2. 客户端状态管理
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
'use client';
|
|
251
|
+
|
|
252
|
+
// 1. 使用 Store 管理状态
|
|
253
|
+
@injectable()
|
|
254
|
+
export class UserProfileStore extends StoreInterface<UserProfileState> {
|
|
255
|
+
constructor() {
|
|
256
|
+
super(() => ({
|
|
257
|
+
user: null,
|
|
258
|
+
loading: false,
|
|
259
|
+
error: null
|
|
260
|
+
}));
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
async fetchUser(id: string) {
|
|
264
|
+
this.emit({ ...this.state, loading: true });
|
|
265
|
+
try {
|
|
266
|
+
const user = await this.userService.getUser(id);
|
|
267
|
+
this.emit({ ...this.state, user, loading: false });
|
|
268
|
+
} catch (error) {
|
|
269
|
+
this.emit({ ...this.state, error, loading: false });
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// 2. 在组件中使用 Store
|
|
275
|
+
export function UserProfile() {
|
|
276
|
+
const store = useIOC(UserProfileStore);
|
|
277
|
+
const user = useStore(store, store.selector.user);
|
|
278
|
+
const loading = useStore(store, store.selector.loading);
|
|
279
|
+
|
|
280
|
+
return (
|
|
281
|
+
<div>
|
|
282
|
+
{loading ? <Loading /> : <UserInfo user={user} />}
|
|
283
|
+
</div>
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
## 页面路由和元数据
|
|
289
|
+
|
|
290
|
+
### 1. 动态路由
|
|
291
|
+
|
|
292
|
+
```typescript
|
|
293
|
+
// app/[locale]/users/[id]/page.tsx
|
|
294
|
+
export default async function UserPage({
|
|
295
|
+
params: { locale, id }
|
|
296
|
+
}: {
|
|
297
|
+
params: { locale: string; id: string };
|
|
298
|
+
}) {
|
|
299
|
+
// 处理路由参数
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// 生成静态路由
|
|
303
|
+
export async function generateStaticParams() {
|
|
304
|
+
const users = await fetchUsers();
|
|
305
|
+
|
|
306
|
+
return users.map((user) => ({
|
|
307
|
+
locale: ['en', 'zh'],
|
|
308
|
+
id: user.id
|
|
309
|
+
}));
|
|
310
|
+
}
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
### 2. 元数据生成
|
|
314
|
+
|
|
315
|
+
```typescript
|
|
316
|
+
// 1. 静态元数据
|
|
317
|
+
export const metadata: Metadata = {
|
|
318
|
+
title: 'User Profile',
|
|
319
|
+
description: 'User profile page'
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
// 2. 动态元数据
|
|
323
|
+
export async function generateMetadata({
|
|
324
|
+
params
|
|
325
|
+
}: {
|
|
326
|
+
params: PageParamsType;
|
|
327
|
+
}): Promise<Metadata> {
|
|
328
|
+
const pageParams = new PageParams(await params);
|
|
329
|
+
const tt = await pageParams.getI18nInterface(userI18n);
|
|
330
|
+
|
|
331
|
+
return {
|
|
332
|
+
title: tt.pageTitle,
|
|
333
|
+
description: tt.pageDescription
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
## 最佳实践和性能优化
|
|
339
|
+
|
|
340
|
+
### 1. 组件分割原则
|
|
341
|
+
|
|
342
|
+
```typescript
|
|
343
|
+
// ❌ 错误:在一个组件中混合服务端和客户端逻辑
|
|
344
|
+
export default function Page() {
|
|
345
|
+
const [state, setState] = useState(); // 错误:服务端组件不能使用 hooks
|
|
346
|
+
const data = await fetchData(); // 正确:服务端数据获取
|
|
347
|
+
|
|
348
|
+
return <div>{/* ... */}</div>;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// ✅ 正确:分离服务端和客户端逻辑
|
|
352
|
+
// page.tsx (服务端组件)
|
|
353
|
+
export default async function Page() {
|
|
354
|
+
const data = await fetchData(); // 服务端数据获取
|
|
355
|
+
return <ClientComponent data={data} />;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// ClientComponent.tsx (客户端组件)
|
|
359
|
+
'use client';
|
|
360
|
+
export function ClientComponent({ data }) {
|
|
361
|
+
const [state, setState] = useState(); // 客户端状态管理
|
|
362
|
+
return <div>{/* ... */}</div>;
|
|
363
|
+
}
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
### 2. 性能优化策略
|
|
367
|
+
|
|
368
|
+
```typescript
|
|
369
|
+
// 1. 组件级缓存
|
|
370
|
+
export default async function UserList() {
|
|
371
|
+
const users = await fetchUsers();
|
|
372
|
+
|
|
373
|
+
return (
|
|
374
|
+
<div>
|
|
375
|
+
{users.map(user => (
|
|
376
|
+
<Suspense key={user.id} fallback={<Loading />}>
|
|
377
|
+
<UserCard user={user} />
|
|
378
|
+
</Suspense>
|
|
379
|
+
))}
|
|
380
|
+
</div>
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// 2. 路由级缓存
|
|
385
|
+
export const revalidate = 3600; // 缓存一小时
|
|
386
|
+
|
|
387
|
+
// 3. 选择性水合
|
|
388
|
+
export default function Page() {
|
|
389
|
+
return (
|
|
390
|
+
<>
|
|
391
|
+
<StaticContent />
|
|
392
|
+
<Suspense fallback={<Loading />}>
|
|
393
|
+
<DynamicContent />
|
|
394
|
+
</Suspense>
|
|
395
|
+
</>
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
### 3. 错误处理
|
|
401
|
+
|
|
402
|
+
```typescript
|
|
403
|
+
// 1. 错误边界
|
|
404
|
+
'use client';
|
|
405
|
+
export function ErrorBoundary({
|
|
406
|
+
error,
|
|
407
|
+
reset
|
|
408
|
+
}: {
|
|
409
|
+
error: Error;
|
|
410
|
+
reset: () => void;
|
|
411
|
+
}) {
|
|
412
|
+
return (
|
|
413
|
+
<div>
|
|
414
|
+
<h2>出错了!</h2>
|
|
415
|
+
<button onClick={reset}>重试</button>
|
|
416
|
+
</div>
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// 2. 加载状态
|
|
421
|
+
export default async function Page() {
|
|
422
|
+
return (
|
|
423
|
+
<Suspense fallback={<Loading />}>
|
|
424
|
+
<SlowComponent />
|
|
425
|
+
</Suspense>
|
|
426
|
+
);
|
|
427
|
+
}
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
## 总结
|
|
431
|
+
|
|
432
|
+
Next.js 13+ 的页面开发需要注意以下几点:
|
|
433
|
+
|
|
434
|
+
1. **组件类型选择**:
|
|
435
|
+
- 默认使用服务端组件
|
|
436
|
+
- 只在必要时使用客户端组件
|
|
437
|
+
- 合理分割组件职责
|
|
438
|
+
|
|
439
|
+
2. **数据流处理**:
|
|
440
|
+
- 服务端优先获取数据
|
|
441
|
+
- 通过属性传递给客户端
|
|
442
|
+
- 使用 Store 管理客户端状态
|
|
443
|
+
|
|
444
|
+
3. **性能优化**:
|
|
445
|
+
- 合理使用缓存策略
|
|
446
|
+
- 实现选择性水合
|
|
447
|
+
- 优化加载性能
|
|
448
|
+
|
|
449
|
+
4. **开发体验**:
|
|
450
|
+
- 清晰的代码组织
|
|
451
|
+
- 类型安全
|
|
452
|
+
- 完善的错误处理
|
|
453
|
+
|
|
454
|
+
5. **最佳实践**:
|
|
455
|
+
- 遵循单一职责原则
|
|
456
|
+
- 实现优雅降级
|
|
457
|
+
- 保持代码可维护性
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# 项目结构详细说明
|
|
2
|
+
|
|
3
|
+
## 目录结构概览
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
next-app/
|
|
7
|
+
├── config/ # 全局配置文件
|
|
8
|
+
├── src/ # 源代码目录
|
|
9
|
+
│ ├── app/ # Next.js 应用路由
|
|
10
|
+
│ ├── base/ # 客户端核心代码
|
|
11
|
+
│ ├── core/ # 核心启动和IOC配置
|
|
12
|
+
│ ├── server/ # 服务端代码
|
|
13
|
+
│ ├── styles/ # 样式文件
|
|
14
|
+
│ └── uikit/ # UI组件库
|
|
15
|
+
└── public/ # 静态资源
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## 详细结构说明
|
|
19
|
+
|
|
20
|
+
### 1. 客户端架构 (src/base)
|
|
21
|
+
|
|
22
|
+
#### 1.1 接口层 (src/base/port)
|
|
23
|
+
|
|
24
|
+
- `AdminLayoutInterface.ts` - 管理布局接口
|
|
25
|
+
- `AppApiInterface.ts` - 应用API接口
|
|
26
|
+
- `AppUserApiInterface.ts` - 用户API接口
|
|
27
|
+
- `AsyncStateInterface.ts` - 异步状态接口
|
|
28
|
+
- `I18nServiceInterface.ts` - 国际化服务接口
|
|
29
|
+
- `IOCInterface.ts` - 依赖注入接口
|
|
30
|
+
- `RouterInterface.ts` - 路由接口
|
|
31
|
+
- `UserServiceInterface.ts` - 用户服务接口
|
|
32
|
+
|
|
33
|
+
#### 1.2 业务逻辑层 (src/base/cases)
|
|
34
|
+
|
|
35
|
+
- 状态管理控制器
|
|
36
|
+
- 对话框处理
|
|
37
|
+
- 路由服务
|
|
38
|
+
- 用户服务
|
|
39
|
+
- 加密服务
|
|
40
|
+
|
|
41
|
+
#### 1.3 服务实现层 (src/base/services)
|
|
42
|
+
|
|
43
|
+
- `AdminUserService.ts` - 管理用户服务
|
|
44
|
+
- `I18nService.ts` - 国际化服务
|
|
45
|
+
- `UserService.ts` - 用户服务
|
|
46
|
+
- `adminApi/` - 管理API实现
|
|
47
|
+
- `appApi/` - 应用API实现
|
|
48
|
+
|
|
49
|
+
### 2. 服务端架构 (src/server)
|
|
50
|
+
|
|
51
|
+
#### 2.1 接口层 (src/server/port)
|
|
52
|
+
|
|
53
|
+
- `CrentialTokenInterface.ts` - 凭证令牌接口
|
|
54
|
+
- `DBBridgeInterface.ts` - 数据库桥接接口
|
|
55
|
+
- `DBTableInterface.ts` - 数据表接口
|
|
56
|
+
- `PaginationInterface.ts` - 分页接口
|
|
57
|
+
- `ParamsHandlerInterface.ts` - 参数处理接口
|
|
58
|
+
- `ServerAuthInterface.ts` - 服务认证接口
|
|
59
|
+
- `ServerInterface.ts` - 服务器接口
|
|
60
|
+
- `UserRepositoryInterface.ts` - 用户仓库接口
|
|
61
|
+
- `ValidatorInterface.ts` - 验证器接口
|
|
62
|
+
|
|
63
|
+
#### 2.2 核心实现
|
|
64
|
+
|
|
65
|
+
- `AppErrorApi.ts` - API错误处理
|
|
66
|
+
- `AppSuccessApi.ts` - API成功响应
|
|
67
|
+
- `ServerAuth.ts` - 服务认证实现
|
|
68
|
+
- `UserCredentialToken.ts` - 用户凭证令牌
|
|
69
|
+
|
|
70
|
+
#### 2.3 服务层 (src/server/services)
|
|
71
|
+
|
|
72
|
+
- `AdminAuthPlugin.ts` - 管理认证插件
|
|
73
|
+
- `AIService.ts` - AI服务
|
|
74
|
+
- `ApiUserService.ts` - API用户服务
|
|
75
|
+
- `UserService.ts` - 用户服务
|
|
76
|
+
|
|
77
|
+
#### 2.4 数据访问层
|
|
78
|
+
|
|
79
|
+
- `repositorys/UserRepository.ts` - 用户数据仓库
|
|
80
|
+
- `sqlBridges/SupabaseBridge.ts` - Supabase数据库桥接
|
|
81
|
+
|
|
82
|
+
#### 2.5 验证器 (src/server/validators)
|
|
83
|
+
|
|
84
|
+
- `LoginValidator.ts` - 登录验证
|
|
85
|
+
- `PaginationValidator.ts` - 分页验证
|
|
86
|
+
|
|
87
|
+
### 3. API路由结构 (src/app/api)
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
api/
|
|
91
|
+
├── admin/ # 管理接口
|
|
92
|
+
│ └── users/ # 用户管理
|
|
93
|
+
├── ai/ # AI相关接口
|
|
94
|
+
│ └── completions/ # AI补全
|
|
95
|
+
└── user/ # 用户接口
|
|
96
|
+
├── login/ # 登录
|
|
97
|
+
├── logout/ # 登出
|
|
98
|
+
└── register/ # 注册
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### 4. 页面路由结构 (src/app/[locale])
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
[locale]/
|
|
105
|
+
├── admin/ # 管理页面
|
|
106
|
+
│ └── users/ # 用户管理
|
|
107
|
+
├── login/ # 登录页面
|
|
108
|
+
├── register/ # 注册页面
|
|
109
|
+
└── page.tsx # 首页
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### 5. UI组件库 (src/uikit)
|
|
113
|
+
|
|
114
|
+
#### 5.1 组件 (components)
|
|
115
|
+
|
|
116
|
+
- `AdminLayout.tsx` - 管理布局
|
|
117
|
+
- `BaseHeader.tsx` - 基础头部
|
|
118
|
+
- `BaseLayout.tsx` - 基础布局
|
|
119
|
+
- `ChatRoot.tsx` - 聊天根组件
|
|
120
|
+
- `LanguageSwitcher.tsx` - 语言切换
|
|
121
|
+
- `ThemeSwitcher.tsx` - 主题切换
|
|
122
|
+
- 其他通用组件
|
|
123
|
+
|
|
124
|
+
#### 5.2 Hooks和Context
|
|
125
|
+
|
|
126
|
+
- `useI18nInterface.ts` - 国际化Hook
|
|
127
|
+
- `useIOC.ts` - IOC容器Hook
|
|
128
|
+
- `useStore.ts` - 状态管理Hook
|
|
129
|
+
- `IOCContext.ts` - IOC上下文
|
|
130
|
+
|
|
131
|
+
## 技术特点
|
|
132
|
+
|
|
133
|
+
1. **依赖注入模式**
|
|
134
|
+
- 使用 IOC 容器管理依赖
|
|
135
|
+
- 客户端和服务端分别维护独立的 IOC 容器
|
|
136
|
+
- 通过接口进行解耦
|
|
137
|
+
|
|
138
|
+
2. **分层架构**
|
|
139
|
+
- 清晰的接口定义
|
|
140
|
+
- 职责分明的实现层
|
|
141
|
+
- 松耦合的模块设计
|
|
142
|
+
|
|
143
|
+
3. **状态管理**
|
|
144
|
+
- 基于控制器的状态管理
|
|
145
|
+
- 响应式数据流
|
|
146
|
+
- 可预测的状态变更
|
|
147
|
+
|
|
148
|
+
4. **国际化支持**
|
|
149
|
+
- 基于 next-intl 的多语言支持
|
|
150
|
+
- 动态语言切换
|
|
151
|
+
- 路由级别的语言隔离
|
|
152
|
+
|
|
153
|
+
5. **主题系统**
|
|
154
|
+
- 基于 Tailwind CSS
|
|
155
|
+
- 暗黑模式支持
|
|
156
|
+
- 可配置的主题变量
|
|
157
|
+
|
|
158
|
+
## 开发流程
|
|
159
|
+
|
|
160
|
+
1. **API开发**
|
|
161
|
+
- 定义接口 (port)
|
|
162
|
+
- 实现验证器 (validators)
|
|
163
|
+
- 实现服务 (services)
|
|
164
|
+
- 创建API路由 (api)
|
|
165
|
+
|
|
166
|
+
2. **页面开发**
|
|
167
|
+
- 创建页面组件
|
|
168
|
+
- 实现控制器
|
|
169
|
+
- 注册依赖
|
|
170
|
+
- 添加路由
|
|
171
|
+
|
|
172
|
+
3. **组件开发**
|
|
173
|
+
- 创建UI组件
|
|
174
|
+
- 实现业务逻辑
|
|
175
|
+
- 注入依赖
|
|
176
|
+
- 添加样式
|