@qlover/create-app 0.3.2 → 0.3.4
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 +139 -0
- package/package.json +4 -4
- package/templates/react-app/README.md +311 -120
- package/templates/react-app/config/Identifier.I18n.ts +1048 -0
- package/templates/react-app/config/app.router.json +7 -7
- package/templates/react-app/config/common.ts +13 -0
- package/templates/react-app/config/theme.json +7 -88
- package/templates/react-app/package.json +11 -5
- package/templates/react-app/postcss.config.js +1 -2
- package/templates/react-app/public/locales/en/common.json +142 -1
- package/templates/react-app/public/locales/zh/common.json +142 -1
- package/templates/react-app/src/App.tsx +16 -3
- package/templates/react-app/src/base/apis/AiApi.ts +4 -4
- package/templates/react-app/src/base/apis/feApi/FeApiAdapter.ts +2 -2
- package/templates/react-app/src/base/apis/userApi/UserApiAdapter.ts +2 -2
- package/templates/react-app/src/base/cases/AppConfig.ts +103 -0
- package/templates/react-app/src/base/cases/{appError/AppError.ts → AppError.ts} +0 -3
- package/templates/react-app/src/base/cases/DialogHandler.ts +86 -0
- package/templates/react-app/src/base/cases/RequestLogger.ts +1 -1
- package/templates/react-app/src/base/cases/RouterLoader.ts +166 -0
- package/templates/react-app/src/base/port/InteractionHubInterface.ts +94 -0
- package/templates/react-app/src/base/services/I18nService.ts +50 -3
- package/templates/react-app/src/base/services/ProcesserService.ts +0 -1
- package/templates/react-app/src/base/types/deprecated-antd.d.ts +60 -0
- package/templates/react-app/src/core/IOC.ts +18 -8
- package/templates/react-app/src/core/bootstrap.ts +41 -62
- package/templates/react-app/src/core/bootstraps/PrintBootstrap.ts +14 -0
- package/templates/react-app/src/core/bootstraps/index.ts +36 -7
- package/templates/react-app/src/core/globals.ts +8 -1
- package/templates/react-app/src/core/registers/RegisterApi.ts +2 -5
- package/templates/react-app/src/core/registers/RegisterCommon.ts +38 -29
- package/templates/react-app/src/core/registers/RegisterControllers.ts +5 -10
- package/templates/react-app/src/core/registers/RegisterGlobals.ts +21 -17
- package/templates/react-app/src/core/registers/index.ts +27 -13
- package/templates/react-app/src/main.tsx +1 -1
- package/templates/react-app/src/pages/404.tsx +1 -1
- package/templates/react-app/src/pages/500.tsx +1 -1
- package/templates/react-app/src/pages/auth/Login.tsx +128 -36
- package/templates/react-app/src/pages/base/About.tsx +118 -2
- package/templates/react-app/src/pages/base/ErrorIdentifier.tsx +38 -19
- package/templates/react-app/src/pages/base/Executor.tsx +442 -29
- package/templates/react-app/src/pages/base/Home.tsx +99 -93
- package/templates/react-app/src/pages/base/JSONStorage.tsx +47 -38
- package/templates/react-app/src/pages/base/Layout.tsx +5 -2
- package/templates/react-app/src/pages/base/Request.tsx +90 -208
- package/templates/react-app/src/pages/base/components/BaseHeader.tsx +13 -5
- package/templates/react-app/src/styles/css/antd-themes/_default.css +239 -0
- package/templates/react-app/src/styles/css/antd-themes/dark.css +176 -0
- package/templates/react-app/src/styles/css/antd-themes/index.css +3 -0
- package/templates/react-app/src/styles/css/antd-themes/no-context.css +34 -0
- package/templates/react-app/src/styles/css/antd-themes/pink.css +199 -0
- package/templates/react-app/src/{uikit/styles → styles}/css/index.css +3 -0
- package/templates/react-app/src/styles/css/page.css +11 -0
- package/templates/react-app/src/styles/css/tailwind.css +5 -0
- package/templates/react-app/src/styles/css/themes/_default.css +29 -0
- package/templates/react-app/src/styles/css/themes/dark.css +29 -0
- package/templates/react-app/src/styles/css/themes/index.css +3 -0
- package/templates/react-app/src/styles/css/themes/pink.css +29 -0
- package/templates/react-app/src/uikit/components/LanguageSwitcher.tsx +56 -0
- package/templates/react-app/src/uikit/components/Loading.tsx +27 -21
- package/templates/react-app/src/uikit/components/RouterRenderComponent.tsx +1 -1
- package/templates/react-app/src/uikit/components/ThemeSwitcher.tsx +63 -13
- package/templates/react-app/src/uikit/contexts/BaseRouteContext.ts +1 -1
- package/templates/react-app/src/uikit/controllers/RouterController.ts +1 -1
- package/templates/react-app/src/uikit/controllers/UserController.ts +2 -2
- package/templates/react-app/tailwind.config.js +1 -15
- package/templates/react-app/tsconfig.json +3 -2
- package/templates/react-app/tsconfig.node.json +2 -1
- package/templates/react-app/vite.config.ts +15 -3
- package/templates/react-app/lib/tailwind/root10px.js +0 -178
- package/templates/react-app/lib/tailwind/theme-generator.js +0 -238
- package/templates/react-app/public/locales/en/about.json +0 -3
- package/templates/react-app/public/locales/en/executor.json +0 -6
- package/templates/react-app/public/locales/en/home.json +0 -10
- package/templates/react-app/public/locales/en/jsonStorage.json +0 -11
- package/templates/react-app/public/locales/en/login.json +0 -7
- package/templates/react-app/public/locales/en/request.json +0 -15
- package/templates/react-app/public/locales/zh/about.json +0 -3
- package/templates/react-app/public/locales/zh/executor.json +0 -6
- package/templates/react-app/public/locales/zh/home.json +0 -10
- package/templates/react-app/public/locales/zh/jsonStorage.json +0 -11
- package/templates/react-app/public/locales/zh/login.json +0 -7
- package/templates/react-app/public/locales/zh/request.json +0 -15
- package/templates/react-app/src/base/cases/router-loader/index.ts +0 -90
- package/templates/react-app/src/base/port/InversifyIocInterface.ts +0 -9
- package/templates/react-app/src/core/AppConfig.ts +0 -36
- package/templates/react-app/src/uikit/styles/css/page.css +0 -3
- package/templates/react-app/src/uikit/styles/css/tailwind.css +0 -3
- /package/templates/react-app/config/{ErrorIdentifier.ts → Identifier.Error.ts} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,144 @@
|
|
|
1
1
|
# @qlover/create-app
|
|
2
2
|
|
|
3
|
+
## 0.3.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
#### ✨ Features
|
|
8
|
+
|
|
9
|
+
- enhance React app with Ant Design integration and theming improvements ([374eaa3](https://github.com/qlover/fe-base/commit/374eaa36ab85b71543668721888823c41793aa23)) ([#414](https://github.com/qlover/fe-base/pull/414))
|
|
10
|
+
|
|
11
|
+
- Added Vite as a dependency for improved build performance.
|
|
12
|
+
- Introduced new Ant Design components and updated existing ones for a consistent UI experience.
|
|
13
|
+
- Enhanced theming capabilities with new CSS variables and custom themes (default, dark, pink).
|
|
14
|
+
- Updated localization keys for the About page and added new messages for better user feedback.
|
|
15
|
+
- Refactored DialogHandler to manage Ant Design's static APIs globally.
|
|
16
|
+
- Improved overall code structure and organization for better maintainability.
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
Co-authored-by: QRJ <renjie.qin@brain.im>
|
|
20
|
+
|
|
21
|
+
- enhance React app with improved configuration management and new components ([67f88cb](https://github.com/qlover/fe-base/commit/67f88cbc7cc0ebab51cbd33be66f98117fc2cf21)) ([#414](https://github.com/qlover/fe-base/pull/414))
|
|
22
|
+
|
|
23
|
+
- Introduced centralized AppConfig class for managing application settings and environment variables.
|
|
24
|
+
- Added DialogHandler for handling notifications and confirmations using Ant Design components.
|
|
25
|
+
- Refactored RouterLoader to support dynamic route configurations and lazy loading of components.
|
|
26
|
+
- Updated various API adapters to utilize the new AppConfig structure for better maintainability.
|
|
27
|
+
- Removed outdated DialogHandler implementation and reorganized related files for improved clarity.
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
Co-authored-by: QRJ <renjie.qin@brain.im>
|
|
31
|
+
|
|
32
|
+
- integrate @brain-toolkit/antd-theme-override for improved Ant D… ([4ebb081](https://github.com/qlover/fe-base/commit/4ebb081d89397424c459dd7f885817152098e322)) ([#414](https://github.com/qlover/fe-base/pull/414))
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
* feat: integrate @brain-toolkit/antd-theme-override for improved Ant Design support
|
|
36
|
+
|
|
37
|
+
- Added @brain-toolkit/antd-theme-override as a dependency to enhance theming capabilities.
|
|
38
|
+
- Updated imports to utilize the new theming library, replacing the deprecated antd-overried references.
|
|
39
|
+
- Removed outdated files related to the previous Ant Design integration to streamline the codebase.
|
|
40
|
+
- Refactored components to leverage the new theme provider and static API interface for notifications and modals.
|
|
41
|
+
|
|
42
|
+
Co-authored-by: QRJ <renjie.qin@brain.im>
|
|
43
|
+
|
|
44
|
+
* feat(I18nService): add translation method for improved localization support
|
|
45
|
+
|
|
46
|
+
- Implemented a new `t` method in the I18nService class to facilitate key-based translations.
|
|
47
|
+
- The method accepts a translation key and optional parameters, returning the translated value or the key if no translation is found.
|
|
48
|
+
- Enhanced localization handling to improve user experience across the application.
|
|
49
|
+
|
|
50
|
+
---------
|
|
51
|
+
|
|
52
|
+
Co-authored-by: QRJ <renjie.qin@brain.im>
|
|
53
|
+
|
|
54
|
+
## 0.3.3
|
|
55
|
+
|
|
56
|
+
### Patch Changes
|
|
57
|
+
|
|
58
|
+
#### ✨ Features
|
|
59
|
+
|
|
60
|
+
- **LanguageSwitcher:** add language switcher component to enhance localization ([72edba8](https://github.com/qlover/fe-base/commit/72edba8a71dabba00608fceafc355cf4bc2dfd63)) ([#411](https://github.com/qlover/fe-base/pull/411))
|
|
61
|
+
|
|
62
|
+
- Introduced a new LanguageSwitcher component that allows users to change the application language.
|
|
63
|
+
- Integrated the component into BaseHeader for improved accessibility.
|
|
64
|
+
- Utilized Ant Design's Select component for a user-friendly interface.
|
|
65
|
+
- Implemented language change functionality that updates the URL and i18n configuration accordingly.
|
|
66
|
+
|
|
67
|
+
- **Login:** integrate Ant Design components for enhanced user experience ([d380157](https://github.com/qlover/fe-base/commit/d380157d3360ad5b9e96d0e3edeb2639a3a6ba9f)) ([#408](https://github.com/qlover/fe-base/pull/408))
|
|
68
|
+
|
|
69
|
+
- Added Ant Design library to the project dependencies.
|
|
70
|
+
- Refactored the Login component to utilize Ant Design's Form, Input, and Button components, improving the UI and UX.
|
|
71
|
+
- Implemented a structured login form with validation and Google sign-in option.
|
|
72
|
+
- Enhanced layout with a brand section and feature highlights for better engagement.
|
|
73
|
+
|
|
74
|
+
- update React app with Tailwind CSS integration and Ant Design enhancements ([eff0ae2](https://github.com/qlover/fe-base/commit/eff0ae25eb2f831b2344a9d4307495377dce647f)) ([#408](https://github.com/qlover/fe-base/pull/408))
|
|
75
|
+
|
|
76
|
+
- Added Tailwind CSS and its PostCSS and Vite plugins to the project dependencies.
|
|
77
|
+
- Refactored the PostCSS configuration to utilize the new Tailwind CSS setup.
|
|
78
|
+
- Updated the Tailwind configuration to simplify theme management.
|
|
79
|
+
- Enhanced the Login component with Ant Design's Form and Input components, improving the UI.
|
|
80
|
+
- Introduced a new CSS structure for theming, including default, dark, and pink themes.
|
|
81
|
+
- Removed outdated Tailwind CSS files from the uikit directory to streamline styles.
|
|
82
|
+
|
|
83
|
+
- enhance React app UI with Ant Design components and improve theming ([008e69a](https://github.com/qlover/fe-base/commit/008e69a89ca0ed0fe23d60c2b368fbd88bb3f15c)) ([#408](https://github.com/qlover/fe-base/pull/408))
|
|
84
|
+
|
|
85
|
+
- Replaced various UI elements with Ant Design components for a consistent look and feel.
|
|
86
|
+
- Updated ErrorIdentifier and Executor components to utilize Ant Design's Button and layout features.
|
|
87
|
+
- Refactored styles to leverage CSS variables for better theming across components.
|
|
88
|
+
- Added new task management features in the Executor component, including task creation and status tracking.
|
|
89
|
+
- Improved overall layout and responsiveness of pages with enhanced CSS styling.
|
|
90
|
+
|
|
91
|
+
- enhance localization and error handling in React app ([f8a5398](https://github.com/qlover/fe-base/commit/f8a5398084cde69b967242a1db89d511a4b2b79e)) ([#408](https://github.com/qlover/fe-base/pull/408))
|
|
92
|
+
feat: enhance localization and error handling in React app
|
|
93
|
+
|
|
94
|
+
- Introduced new localization keys for various pages including JSONStorage, Request, and Executor.
|
|
95
|
+
- Updated components to utilize new localization keys for improved internationalization support.
|
|
96
|
+
- Removed outdated error identifiers and added new ones for better clarity and consistency.
|
|
97
|
+
- Enhanced the Home, About, and ErrorIdentifier components with improved localization.
|
|
98
|
+
- Streamlined theme switcher labels to utilize localization keys for better user experience.
|
|
99
|
+
|
|
100
|
+
#### ♻️ Refactors
|
|
101
|
+
|
|
102
|
+
- **Bootstrap:** update dependencies and refactor core components ([9aeff78](https://github.com/qlover/fe-base/commit/9aeff78209925a9e3e6e4cdf1e5a7cbbcecb07f8)) ([#411](https://github.com/qlover/fe-base/pull/411))
|
|
103
|
+
|
|
104
|
+
- Upgraded @qlover/corekit-bridge to version ^1.0.3 in package.json.
|
|
105
|
+
- Refactored startup function to use 'root' instead of 'window' for better compatibility.
|
|
106
|
+
- Removed InversifyIocInterface.ts as it was no longer needed.
|
|
107
|
+
- Enhanced I18nService to manage loading state and language changes more effectively.
|
|
108
|
+
- Introduced BootstrapsRegistry for improved bootstrap management and organization.
|
|
109
|
+
- Updated various register classes to align with new IOC structure and improve dependency injection.
|
|
110
|
+
- Added printBootstrap for logging successful bootstrap initialization.
|
|
111
|
+
|
|
112
|
+
- **Home, JSONStorage, Layout, BaseHeader:** enhance UI with Ant Design components and improve theming ([8023e01](https://github.com/qlover/fe-base/commit/8023e0179729859a1406f5dabf013f529c1a2b58)) ([#408](https://github.com/qlover/fe-base/pull/408))
|
|
113
|
+
|
|
114
|
+
- Replaced button elements with Ant Design's Button component for a consistent UI experience.
|
|
115
|
+
- Updated layout and background colors to utilize CSS variables for better theming.
|
|
116
|
+
- Refactored navigation items in Home component for improved structure and readability.
|
|
117
|
+
- Enhanced JSONStorage component styling and layout for better user interaction.
|
|
118
|
+
- Improved BaseHeader styling with new background and border colors for a modern look.
|
|
119
|
+
|
|
120
|
+
- streamline UI components and enhance theming in React app ([9baf49b](https://github.com/qlover/fe-base/commit/9baf49b60b58f3c3e614f2bf473853a50abeff8e)) ([#408](https://github.com/qlover/fe-base/pull/408))
|
|
121
|
+
|
|
122
|
+
- Consolidated background and text color styles across various components to utilize CSS variables for improved theming.
|
|
123
|
+
- Updated 404 and 500 error pages to align with new color schemes.
|
|
124
|
+
- Refactored Login, About, and Executor components to enhance layout and responsiveness.
|
|
125
|
+
- Improved overall consistency in UI by replacing hardcoded colors with theme variables.
|
|
126
|
+
- Enhanced the Home and JSONStorage components for better user experience and visual appeal.
|
|
127
|
+
|
|
128
|
+
- update localization and error handling in React app ([b5617a1](https://github.com/qlover/fe-base/commit/b5617a1e04770352d92a840a59728a57955475fe)) ([#408](https://github.com/qlover/fe-base/pull/408))
|
|
129
|
+
|
|
130
|
+
- Renamed error identifier files for clarity and consistency.
|
|
131
|
+
- Introduced new localization identifiers for error messages and page content.
|
|
132
|
+
- Updated configuration to reflect new file paths for error handling.
|
|
133
|
+
- Removed outdated localization files to streamline the project structure.
|
|
134
|
+
- Enhanced the Home and About components with improved localization support.
|
|
135
|
+
|
|
136
|
+
- **Loading:** update loading component with animated bouncing dots ([83ede4b](https://github.com/qlover/fe-base/commit/83ede4b644a01843dd64e2d3e5254730f115d1ec)) ([#408](https://github.com/qlover/fe-base/pull/408))
|
|
137
|
+
|
|
138
|
+
- Replaced the SVG spinner with a new loading animation using bouncing dots for improved visual appeal.
|
|
139
|
+
- Utilized the clsx library for conditional class management, enhancing readability and maintainability.
|
|
140
|
+
- Adjusted styles to support dark mode and added backdrop blur for fullscreen loading state.
|
|
141
|
+
|
|
3
142
|
## 0.3.2
|
|
4
143
|
|
|
5
144
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qlover/create-app",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -51,9 +51,9 @@
|
|
|
51
51
|
"inquirer": "^12.3.2",
|
|
52
52
|
"ora": "^8.1.1",
|
|
53
53
|
"lodash": "^4.17.21",
|
|
54
|
-
"@qlover/
|
|
55
|
-
"@qlover/
|
|
56
|
-
"@qlover/
|
|
54
|
+
"@qlover/logger": "0.1.1",
|
|
55
|
+
"@qlover/fe-corekit": "1.4.0",
|
|
56
|
+
"@qlover/scripts-context": "0.2.1"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "rollup -c",
|
|
@@ -2,185 +2,376 @@
|
|
|
2
2
|
|
|
3
3
|
一个现代化的 React 前端项目模板,集成了多项实用功能和最佳实践。
|
|
4
4
|
|
|
5
|
-
## 特性亮点
|
|
5
|
+
## 🌟 特性亮点
|
|
6
6
|
|
|
7
7
|
- 🚀 基于 Vite 的快速开发体验
|
|
8
8
|
- 🎨 集成 Tailwind CSS 的主题系统
|
|
9
|
-
- 🌍
|
|
10
|
-
- 🔄 IOC
|
|
9
|
+
- 🌍 完善的国际化支持(中英文)
|
|
10
|
+
- 🔄 基于 TypeScript 的 IOC 容器
|
|
11
11
|
- 📡 统一的 API 请求处理
|
|
12
12
|
- 🎮 控制器模式的状态管理
|
|
13
|
+
- 📦 使用 pnpm 进行包管理
|
|
14
|
+
- 🧪 内置测试支持
|
|
13
15
|
|
|
14
|
-
## 环境要求
|
|
16
|
+
## 🔧 环境要求
|
|
15
17
|
|
|
16
18
|
- Node.js >= 16
|
|
17
19
|
- pnpm >= 8.0
|
|
18
20
|
|
|
19
|
-
##
|
|
21
|
+
## 📁 项目结构
|
|
22
|
+
|
|
23
|
+
```tree
|
|
24
|
+
├── config/ # 配置文件目录
|
|
25
|
+
│ ├── app.router.json # 路由页面配置
|
|
26
|
+
│ ├── common.ts # 应用通用配置
|
|
27
|
+
│ ├── app.router.json # 路由配置
|
|
28
|
+
│ ├── i18n.ts # 国际化配置
|
|
29
|
+
│ └── theme.json # 主题配置
|
|
30
|
+
├── lib/ # 公共库目录
|
|
31
|
+
├── public/ # 静态资源目录
|
|
32
|
+
├── src/
|
|
33
|
+
│ ├── base/ # 基础代码
|
|
34
|
+
│ ├── core/ # 核心代码
|
|
35
|
+
│ ├── pages/ # 页面组件
|
|
36
|
+
│ ├── services/ # 服务层
|
|
37
|
+
│ └── uikit/ # UI 组件库
|
|
38
|
+
└── vite.config.ts # Vite 配置文件
|
|
39
|
+
```
|
|
20
40
|
|
|
21
|
-
|
|
41
|
+
## 🚀 快速开始
|
|
22
42
|
|
|
23
|
-
|
|
24
|
-
- `app.router.json`: 路由配置,定义应用的路由结构
|
|
25
|
-
- `i18n.ts`: 国际化配置,支持中英文切换
|
|
26
|
-
- `theme.json`: 主题配置,定义应用的主题系统
|
|
43
|
+
### 安装依赖
|
|
27
44
|
|
|
28
|
-
|
|
45
|
+
```bash
|
|
46
|
+
pnpm install
|
|
47
|
+
```
|
|
29
48
|
|
|
30
|
-
|
|
31
|
-
│ ├── app.common.ts # 应用通用配置
|
|
32
|
-
│ ├── app.router.json # 路由配置
|
|
33
|
-
│ ├── i18n.ts # 国际化配置
|
|
34
|
-
│ └── theme.json # 主题配置
|
|
35
|
-
├── lib/ # 公共库目录
|
|
36
|
-
│ ├── fe-react-controller/ # React 控制器库
|
|
37
|
-
│ ├── fe-react-theme/ # React 主题库
|
|
38
|
-
│ ├── openAiApi/ # OpenAI API 封装
|
|
39
|
-
│ ├── request-common-plugin/ # 请求公共插件
|
|
40
|
-
│ └── tw-root10px/ # Tailwind 10px 根字体配置
|
|
41
|
-
├── public/ # 静态资源目录
|
|
42
|
-
│ └── locales/ # 国际化资源文件
|
|
43
|
-
├── src/ # 源代码目录
|
|
44
|
-
│ ├── base/ # 基础代码
|
|
45
|
-
│ │ ├── apis/ # API 接口定义
|
|
46
|
-
│ │ ├── cases/ # 业务用例
|
|
47
|
-
│ │ ├── port/ # 接口定义
|
|
48
|
-
│ │ └── types/ # 类型定义
|
|
49
|
-
│ ├── core/ # 核心代码
|
|
50
|
-
│ │ └── feIOC/ # IOC 容器实现
|
|
51
|
-
│ │ └── globals.ts # 全局变量
|
|
52
|
-
│ │ └── bootstrap.ts # 启动器
|
|
53
|
-
│ ├── pages/ # 页面组件
|
|
54
|
-
│ ├── services/ # 服务层
|
|
55
|
-
│ └── uikit/ # UI 组件库
|
|
56
|
-
└── vite.config.ts # Vite 配置文件
|
|
49
|
+
### 开发模式
|
|
57
50
|
|
|
58
|
-
|
|
51
|
+
```bash
|
|
52
|
+
pnpm dev
|
|
53
|
+
```
|
|
59
54
|
|
|
60
|
-
|
|
61
|
-
2. `lib/`: 可复用的独立功能库,方便跨项目使用
|
|
62
|
-
3. `src/base/`: 基础代码层,定义接口和类型
|
|
63
|
-
4. `src/core/`: 核心功能实现,包含 IOC 容器等基础设施
|
|
64
|
-
5. `src/pages/`: 页面组件,按功能模块组织
|
|
65
|
-
6. `src/services/`: 服务层,处理业务逻辑
|
|
66
|
-
7. `src/uikit/`: UI 组件库,提供可复用的界面组件
|
|
55
|
+
### 构建项目
|
|
67
56
|
|
|
68
|
-
|
|
57
|
+
```bash
|
|
58
|
+
pnpm build
|
|
59
|
+
```
|
|
69
60
|
|
|
70
|
-
###
|
|
61
|
+
### 运行测试
|
|
71
62
|
|
|
72
|
-
|
|
63
|
+
```bash
|
|
64
|
+
pnpm test
|
|
65
|
+
```
|
|
73
66
|
|
|
74
|
-
|
|
75
|
-
- `RegisterApi`: API 服务注册
|
|
76
|
-
- `RegisterCommon`: 通用服务注册
|
|
77
|
-
- `RegisterControllers`: 控制器注册
|
|
67
|
+
## 🔨 核心功能
|
|
78
68
|
|
|
79
|
-
###
|
|
69
|
+
### IOC 容器
|
|
80
70
|
|
|
81
|
-
-
|
|
82
|
-
-
|
|
83
|
-
-
|
|
71
|
+
- 基于 TypeScript 的依赖注入系统
|
|
72
|
+
- 支持服务自动注册和依赖管理
|
|
73
|
+
- 提供完整的类型推导
|
|
84
74
|
|
|
85
|
-
###
|
|
75
|
+
### 国际化支持
|
|
86
76
|
|
|
87
|
-
-
|
|
88
|
-
-
|
|
89
|
-
-
|
|
77
|
+
- 基于 i18next 的完整国际化解决方案
|
|
78
|
+
- 支持中文(zh)和英文(en)双语切换
|
|
79
|
+
- 基于 TypeScript 注释的自动国际化资源生成
|
|
80
|
+
- URL 路径语言检测和切换
|
|
81
|
+
- 内置语言切换组件
|
|
90
82
|
|
|
91
|
-
|
|
83
|
+
#### 国际化配置
|
|
92
84
|
|
|
93
|
-
-
|
|
94
|
-
- 支持请求拦截和响应处理
|
|
95
|
-
- Mock 数据支持
|
|
96
|
-
- OpenAI API 集成
|
|
85
|
+
项目使用 `@brain-toolkit/ts2locales` 插件从 TypeScript 注释自动生成国际化资源:
|
|
97
86
|
|
|
98
|
-
|
|
87
|
+
```typescript
|
|
88
|
+
// config/Identifier.I18n.ts
|
|
89
|
+
export const Messages = {
|
|
90
|
+
/**
|
|
91
|
+
* @description Home page welcome message
|
|
92
|
+
* @localZh 欢迎来到主页
|
|
93
|
+
* @localEn Welcome to the home page
|
|
94
|
+
*/
|
|
95
|
+
HOME_WELCOME: 'home.welcome',
|
|
99
96
|
|
|
100
|
-
|
|
97
|
+
/**
|
|
98
|
+
* @description Get started button text
|
|
99
|
+
* @localZh 开始使用
|
|
100
|
+
* @localEn Get Started
|
|
101
|
+
*/
|
|
102
|
+
HOME_GET_STARTED: 'home.get_started'
|
|
103
|
+
};
|
|
104
|
+
```
|
|
101
105
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
106
|
+
Vite 插件配置:
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
// vite.config.ts
|
|
110
|
+
import ts2Locales from '@brain-toolkit/ts2locales/vite';
|
|
111
|
+
import i18nConfig from './config/i18n';
|
|
112
|
+
|
|
113
|
+
export default defineConfig({
|
|
114
|
+
plugins: [
|
|
115
|
+
ts2Locales({
|
|
116
|
+
locales: i18nConfig.supportedLngs,
|
|
117
|
+
options: [
|
|
118
|
+
{
|
|
119
|
+
source: './config/Identifier.Error.ts',
|
|
120
|
+
target: './public/locales/{{lng}}/common.json'
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
source: './config/Identifier.I18n.ts',
|
|
124
|
+
target: './public/locales/{{lng}}/common.json'
|
|
125
|
+
}
|
|
126
|
+
]
|
|
127
|
+
})
|
|
128
|
+
]
|
|
129
|
+
});
|
|
130
|
+
```
|
|
107
131
|
|
|
108
|
-
|
|
132
|
+
#### 国际化服务
|
|
109
133
|
|
|
110
|
-
|
|
111
|
-
- TypeScript
|
|
112
|
-
- Vite
|
|
113
|
-
- Tailwind CSS
|
|
114
|
-
- i18next
|
|
134
|
+
项目提供了 `I18nService` 用于管理国际化状态和语言切换:
|
|
115
135
|
|
|
116
|
-
|
|
136
|
+
```typescript
|
|
137
|
+
import { I18nService } from '@/base/services/I18nService';
|
|
117
138
|
|
|
118
|
-
|
|
139
|
+
// 获取当前语言
|
|
140
|
+
const currentLang = I18nService.getCurrentLanguage();
|
|
119
141
|
|
|
120
|
-
|
|
121
|
-
|
|
142
|
+
// 切换语言
|
|
143
|
+
await i18nService.changeLanguage('zh');
|
|
122
144
|
```
|
|
123
145
|
|
|
124
|
-
|
|
146
|
+
#### 在组件中使用
|
|
125
147
|
|
|
126
|
-
|
|
148
|
+
```typescript
|
|
149
|
+
import { useBaseRoutePage } from '@/uikit/contexts/BaseRouteContext';
|
|
150
|
+
import * as i18nKeys from '@config/Identifier.I18n';
|
|
127
151
|
|
|
128
|
-
|
|
152
|
+
function MyComponent() {
|
|
153
|
+
const { t } = useBaseRoutePage();
|
|
129
154
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
155
|
+
return (
|
|
156
|
+
<div>
|
|
157
|
+
<h1>{t(i18nKeys.HOME_WELCOME)}</h1>
|
|
158
|
+
<button>{t(i18nKeys.HOME_GET_STARTED)}</button>
|
|
159
|
+
</div>
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
```
|
|
133
163
|
|
|
134
|
-
|
|
164
|
+
#### 语言切换组件
|
|
135
165
|
|
|
136
|
-
|
|
166
|
+
项目提供了开箱即用的语言切换组件:
|
|
137
167
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
- `UserController`: 处理用户认证
|
|
141
|
-
- `ThemeController`: 处理主题切换
|
|
168
|
+
```typescript
|
|
169
|
+
import LanguageSwitcher from '@/uikit/components/LanguageSwitcher';
|
|
142
170
|
|
|
143
|
-
|
|
171
|
+
function Header() {
|
|
172
|
+
return (
|
|
173
|
+
<header>
|
|
174
|
+
<LanguageSwitcher />
|
|
175
|
+
</header>
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
```
|
|
144
179
|
|
|
145
|
-
|
|
180
|
+
#### 最佳实践
|
|
146
181
|
|
|
147
|
-
|
|
148
|
-
- `en/`: 英文语言包
|
|
182
|
+
1. 国际化标识符管理:
|
|
149
183
|
|
|
150
|
-
|
|
184
|
+
- 在 `config/Identifier.I18n.ts` 中集中管理UI文本
|
|
185
|
+
- 在 `config/Identifier.Error.ts` 中集中管理错误信息
|
|
186
|
+
- 使用有意义的 key 命名(如:'page.home.title')
|
|
151
187
|
|
|
152
|
-
|
|
153
|
-
pnpm install
|
|
154
|
-
```
|
|
188
|
+
2. TypeScript 注释规范:
|
|
155
189
|
|
|
156
|
-
|
|
190
|
+
- 使用 `@description` 描述文本用途
|
|
191
|
+
- 使用 `@localZh` 定义中文文本
|
|
192
|
+
- 使用 `@localEn` 定义英文文本
|
|
157
193
|
|
|
158
|
-
|
|
159
|
-
pnpm run dev
|
|
160
|
-
```
|
|
194
|
+
3. 路由配置:
|
|
161
195
|
|
|
162
|
-
|
|
196
|
+
- 使用 `LocaleLink` 组件进行页面跳转
|
|
197
|
+
- URL 格式:`/{lang}/path`(如:'/zh/about')
|
|
163
198
|
|
|
164
|
-
|
|
165
|
-
|
|
199
|
+
4. 组件开发:
|
|
200
|
+
- 使用 `useBaseRoutePage` hook 获取翻译函数
|
|
201
|
+
- 从 `@config/Identifier.I18n` 引入国际化 key
|
|
202
|
+
- 避免硬编码文本,始终使用国际化 key
|
|
203
|
+
|
|
204
|
+
### 主题系统
|
|
205
|
+
|
|
206
|
+
- 基于 Tailwind CSS 的主题配置
|
|
207
|
+
- 支持暗色/亮色模式
|
|
208
|
+
- 自定义设计令牌系统
|
|
209
|
+
|
|
210
|
+
### API 集成
|
|
211
|
+
|
|
212
|
+
项目提供了强大的 API 请求处理机制,基于插件化架构设计:
|
|
213
|
+
|
|
214
|
+
#### 请求控制器
|
|
215
|
+
|
|
216
|
+
使用 `RequestController` 统一管理 API 请求:
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
@injectable()
|
|
220
|
+
export class RequestController extends SliceStore<RequestControllerState> {
|
|
221
|
+
constructor(
|
|
222
|
+
@inject(FeApi) private readonly feApi: FeApi,
|
|
223
|
+
@inject(UserApi) private readonly userApi: UserApi
|
|
224
|
+
) {
|
|
225
|
+
super(createDefaultState);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// API 调用示例
|
|
229
|
+
async onRandomUser() {
|
|
230
|
+
if (this.state.randomUserState.loading) return;
|
|
231
|
+
|
|
232
|
+
this.setState({
|
|
233
|
+
randomUserState: { loading: true, result: null, error: null }
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
try {
|
|
237
|
+
const result = await this.userApi.getRandomUser();
|
|
238
|
+
this.setState({
|
|
239
|
+
randomUserState: { loading: false, result, error: null }
|
|
240
|
+
});
|
|
241
|
+
} catch (error) {
|
|
242
|
+
this.setState({
|
|
243
|
+
randomUserState: { loading: false, result: null, error }
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
166
248
|
```
|
|
167
249
|
|
|
168
|
-
|
|
250
|
+
#### 请求插件系统
|
|
251
|
+
|
|
252
|
+
项目内置多个实用的请求插件:
|
|
253
|
+
|
|
254
|
+
1. `FetchURLPlugin`: URL 处理和构建
|
|
255
|
+
2. `RequestCommonPlugin`: 通用请求配置
|
|
256
|
+
3. `ApiMockPlugin`: Mock 数据支持
|
|
257
|
+
4. `FetchAbortPlugin`: 请求中断控制
|
|
258
|
+
5. `RequestLogger`: 请求日志记录
|
|
259
|
+
6. `ApiCatchPlugin`: 统一错误处理
|
|
260
|
+
|
|
261
|
+
使用示例:
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
// 配置请求适配器
|
|
265
|
+
const adapter = new RequestAdapter({
|
|
266
|
+
plugins: [
|
|
267
|
+
new FetchURLPlugin(),
|
|
268
|
+
new RequestCommonPlugin(),
|
|
269
|
+
new ApiMockPlugin(),
|
|
270
|
+
new FetchAbortPlugin(),
|
|
271
|
+
new RequestLogger()
|
|
272
|
+
]
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
// 发起请求
|
|
276
|
+
const response = await adapter.request({
|
|
277
|
+
url: '/api/users',
|
|
278
|
+
method: 'GET',
|
|
279
|
+
requestId: 'uniqueId', // 用于中断请求
|
|
280
|
+
mock: true // 启用 mock 数据
|
|
281
|
+
});
|
|
282
|
+
```
|
|
169
283
|
|
|
170
|
-
|
|
171
|
-
|
|
284
|
+
#### 请求调度器
|
|
285
|
+
|
|
286
|
+
使用 `RequestScheduler` 管理复杂的请求流程:
|
|
287
|
+
|
|
288
|
+
```typescript
|
|
289
|
+
export class FeApi extends RequestScheduler<RequestConfig> {
|
|
290
|
+
async getIpInfo() {
|
|
291
|
+
return this.request<void, IpInfo>({
|
|
292
|
+
url: '/api/ip',
|
|
293
|
+
method: 'GET'
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
}
|
|
172
297
|
```
|
|
173
298
|
|
|
174
|
-
|
|
299
|
+
#### Mock 数据支持
|
|
300
|
+
|
|
301
|
+
项目支持灵活的 Mock 数据配置:
|
|
302
|
+
|
|
303
|
+
```typescript
|
|
304
|
+
// 配置 Mock 数据
|
|
305
|
+
const mockConfig = {
|
|
306
|
+
'/api/users': {
|
|
307
|
+
GET: () => ({
|
|
308
|
+
code: 200,
|
|
309
|
+
data: {
|
|
310
|
+
id: 1,
|
|
311
|
+
name: 'John Doe'
|
|
312
|
+
}
|
|
313
|
+
})
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
// 在请求中使用
|
|
318
|
+
const response = await api.request({
|
|
319
|
+
url: '/api/users',
|
|
320
|
+
method: 'GET',
|
|
321
|
+
mock: true // 启用 mock
|
|
322
|
+
});
|
|
323
|
+
```
|
|
175
324
|
|
|
176
|
-
|
|
325
|
+
#### 最佳实践
|
|
177
326
|
|
|
178
|
-
|
|
327
|
+
1. API 定义:
|
|
179
328
|
|
|
180
|
-
|
|
329
|
+
- 在 `src/base/apis` 中集中管理 API 定义
|
|
330
|
+
- 使用 TypeScript 接口定义请求和响应类型
|
|
331
|
+
- 遵循 RESTful API 设计规范
|
|
181
332
|
|
|
182
|
-
|
|
333
|
+
2. 错误处理:
|
|
183
334
|
|
|
184
|
-
|
|
335
|
+
- 使用 `ApiCatchPlugin` 统一处理错误
|
|
336
|
+
- 定义清晰的错误类型和错误码
|
|
337
|
+
- 提供友好的错误提示
|
|
338
|
+
|
|
339
|
+
3. 请求状态管理:
|
|
340
|
+
|
|
341
|
+
- 使用 `SliceStore` 管理请求状态
|
|
342
|
+
- 处理加载、成功、错误等状态
|
|
343
|
+
- 实现请求防抖和节流
|
|
344
|
+
|
|
345
|
+
4. Mock 数据:
|
|
346
|
+
- 提供合理的 Mock 数据结构
|
|
347
|
+
- 支持动态 Mock 数据生成
|
|
348
|
+
- 便于本地开发和测试
|
|
349
|
+
|
|
350
|
+
### 控制器模式
|
|
351
|
+
|
|
352
|
+
提供多个开箱即用的控制器:
|
|
353
|
+
|
|
354
|
+
- JSONStorageController
|
|
355
|
+
- RequestController
|
|
356
|
+
- RouterController
|
|
357
|
+
- UserController
|
|
358
|
+
- ThemeController
|
|
359
|
+
|
|
360
|
+
## 📚 开发指南
|
|
361
|
+
|
|
362
|
+
### API 开发规范
|
|
363
|
+
|
|
364
|
+
1. 在 `src/base/apis` 定义接口
|
|
365
|
+
2. 支持 Mock 数据配置
|
|
366
|
+
|
|
367
|
+
### 新增页面流程
|
|
368
|
+
|
|
369
|
+
1. 在 `src/pages` 创建页面组件
|
|
370
|
+
2. 更新 `config/app.router.json`
|
|
371
|
+
3. 添加对应的控制器(如需要)
|
|
372
|
+
|
|
373
|
+
### 国际化开发
|
|
185
374
|
|
|
186
|
-
|
|
375
|
+
1. 在 `public/locales` 添加翻译文件
|
|
376
|
+
2. 使用 `useTranslation` hook 进行调用
|
|
377
|
+
3. 支持按需加载语言包
|