@qlover/create-app 0.6.2 → 0.7.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 +53 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/templates/react-app/README.en.md +257 -0
- package/dist/templates/react-app/README.md +29 -231
- package/dist/templates/react-app/__tests__/__mocks__/I18nService.ts +13 -0
- package/dist/templates/react-app/__tests__/__mocks__/MockAppConfit.ts +48 -0
- package/dist/templates/react-app/__tests__/__mocks__/MockDialogHandler.ts +16 -0
- package/dist/templates/react-app/__tests__/__mocks__/MockLogger.ts +14 -0
- package/dist/templates/react-app/__tests__/__mocks__/createMockGlobals.ts +92 -0
- package/dist/templates/react-app/__tests__/setup/index.ts +51 -0
- package/dist/templates/react-app/__tests__/src/App.test.tsx +139 -0
- package/dist/templates/react-app/__tests__/src/base/cases/AppConfig.test.ts +288 -0
- package/dist/templates/react-app/__tests__/src/base/cases/AppError.test.ts +102 -0
- package/dist/templates/react-app/__tests__/src/base/cases/DialogHandler.test.ts +228 -0
- package/dist/templates/react-app/__tests__/src/base/cases/I18nKeyErrorPlugin.test.ts +207 -0
- package/dist/templates/react-app/__tests__/src/base/cases/InversifyContainer.test.ts +181 -0
- package/dist/templates/react-app/__tests__/src/base/cases/PublicAssetsPath.test.ts +61 -0
- package/dist/templates/react-app/__tests__/src/base/cases/RequestLogger.test.ts +199 -0
- package/dist/templates/react-app/__tests__/src/base/cases/RequestStatusCatcher.test.ts +192 -0
- package/dist/templates/react-app/__tests__/src/base/cases/RouterLoader.test.ts +235 -0
- package/dist/templates/react-app/__tests__/src/base/services/I18nService.test.ts +224 -0
- package/dist/templates/react-app/__tests__/src/core/IOC.test.ts +257 -0
- package/dist/templates/react-app/__tests__/src/core/bootstraps/BootstrapsApp.test.ts +72 -0
- package/dist/templates/react-app/__tests__/src/main.integration.test.tsx +62 -0
- package/dist/templates/react-app/__tests__/src/main.test.tsx +46 -0
- package/dist/templates/react-app/__tests__/src/uikit/components/BaseHeader.test.tsx +88 -0
- package/dist/templates/react-app/config/app.router.ts +155 -0
- package/dist/templates/react-app/config/common.ts +9 -1
- package/dist/templates/react-app/docs/en/bootstrap.md +562 -0
- package/dist/templates/react-app/docs/en/development-guide.md +523 -0
- package/dist/templates/react-app/docs/en/env.md +482 -0
- package/dist/templates/react-app/docs/en/global.md +509 -0
- package/dist/templates/react-app/docs/en/i18n.md +268 -0
- package/dist/templates/react-app/docs/en/index.md +173 -0
- package/dist/templates/react-app/docs/en/ioc.md +424 -0
- package/dist/templates/react-app/docs/en/project-structure.md +434 -0
- package/dist/templates/react-app/docs/en/request.md +425 -0
- package/dist/templates/react-app/docs/en/router.md +404 -0
- package/dist/templates/react-app/docs/en/store.md +321 -0
- package/dist/templates/react-app/docs/en/test-guide.md +782 -0
- package/dist/templates/react-app/docs/en/theme.md +424 -0
- package/dist/templates/react-app/docs/en/typescript-guide.md +473 -0
- package/dist/templates/react-app/docs/zh/bootstrap.md +7 -0
- package/dist/templates/react-app/docs/zh/development-guide.md +523 -0
- package/dist/templates/react-app/docs/zh/env.md +24 -25
- package/dist/templates/react-app/docs/zh/global.md +28 -27
- package/dist/templates/react-app/docs/zh/i18n.md +268 -0
- package/dist/templates/react-app/docs/zh/index.md +173 -0
- package/dist/templates/react-app/docs/zh/ioc.md +44 -32
- package/dist/templates/react-app/docs/zh/project-structure.md +434 -0
- package/dist/templates/react-app/docs/zh/request.md +429 -0
- package/dist/templates/react-app/docs/zh/router.md +408 -0
- package/dist/templates/react-app/docs/zh/store.md +321 -0
- package/dist/templates/react-app/docs/zh/test-guide.md +782 -0
- package/dist/templates/react-app/docs/zh/theme.md +424 -0
- package/dist/templates/react-app/docs/zh/typescript-guide.md +473 -0
- package/dist/templates/react-app/package.json +9 -20
- package/dist/templates/react-app/src/base/cases/AppConfig.ts +16 -9
- package/dist/templates/react-app/src/base/cases/PublicAssetsPath.ts +7 -1
- package/dist/templates/react-app/src/base/services/I18nService.ts +15 -4
- package/dist/templates/react-app/src/base/services/RouteService.ts +43 -7
- package/dist/templates/react-app/src/core/bootstraps/BootstrapApp.ts +31 -10
- package/dist/templates/react-app/src/core/bootstraps/BootstrapsRegistry.ts +1 -1
- package/dist/templates/react-app/src/core/globals.ts +1 -3
- package/dist/templates/react-app/src/core/registers/RegisterCommon.ts +5 -3
- package/dist/templates/react-app/src/main.tsx +6 -1
- package/dist/templates/react-app/src/pages/404.tsx +0 -1
- package/dist/templates/react-app/src/pages/500.tsx +1 -1
- package/dist/templates/react-app/src/pages/base/RedirectPathname.tsx +3 -1
- package/dist/templates/react-app/src/styles/css/antd-themes/dark.css +3 -1
- package/dist/templates/react-app/src/styles/css/antd-themes/index.css +1 -1
- package/dist/templates/react-app/src/styles/css/antd-themes/pink.css +6 -1
- package/dist/templates/react-app/src/styles/css/page.css +1 -1
- package/dist/templates/react-app/src/uikit/components/BaseHeader.tsx +9 -2
- package/dist/templates/react-app/src/uikit/components/LocaleLink.tsx +5 -3
- package/dist/templates/react-app/src/uikit/hooks/useI18nGuard.ts +4 -6
- package/dist/templates/react-app/tsconfig.json +2 -1
- package/dist/templates/react-app/tsconfig.test.json +13 -0
- package/dist/templates/react-app/vite.config.ts +3 -2
- package/package.json +1 -1
|
@@ -17,6 +17,8 @@ IOC(Inversion of Control,控制反转)是一种设计模式,它将对象
|
|
|
17
17
|
### 核心文件结构
|
|
18
18
|
|
|
19
19
|
```
|
|
20
|
+
config/
|
|
21
|
+
├── IOCIdentifier.ts # IOC 标识符定义
|
|
20
22
|
src/
|
|
21
23
|
├── core/
|
|
22
24
|
│ ├── IOC.ts # IOC 主入口
|
|
@@ -28,8 +30,6 @@ src/
|
|
|
28
30
|
├── base/
|
|
29
31
|
│ └── cases/
|
|
30
32
|
│ └── InversifyContainer.ts # Inversify 容器实现
|
|
31
|
-
└── config/
|
|
32
|
-
└── IOCIdentifier.ts # IOC 标识符定义
|
|
33
33
|
```
|
|
34
34
|
|
|
35
35
|
## 基本概念
|
|
@@ -42,7 +42,7 @@ export const IOCIdentifier = Object.freeze({
|
|
|
42
42
|
JSON: 'JSON',
|
|
43
43
|
LocalStorage: 'LocalStorage',
|
|
44
44
|
Logger: 'Logger',
|
|
45
|
-
AppConfig: 'AppConfig'
|
|
45
|
+
AppConfig: 'AppConfig'
|
|
46
46
|
// ... 更多标识符
|
|
47
47
|
});
|
|
48
48
|
```
|
|
@@ -53,7 +53,10 @@ export const IOCIdentifier = Object.freeze({
|
|
|
53
53
|
// core/IOC.ts
|
|
54
54
|
export interface IOCIdentifierMap {
|
|
55
55
|
[IOCIdentifier.JSON]: import('@qlover/fe-corekit').JSONSerializer;
|
|
56
|
-
[IOCIdentifier.LocalStorage]: import('@qlover/fe-corekit').ObjectStorage<
|
|
56
|
+
[IOCIdentifier.LocalStorage]: import('@qlover/fe-corekit').ObjectStorage<
|
|
57
|
+
string,
|
|
58
|
+
string
|
|
59
|
+
>;
|
|
57
60
|
[IOCIdentifier.Logger]: import('@qlover/logger').LoggerInterface;
|
|
58
61
|
[IOCIdentifier.AppConfig]: import('@qlover/corekit-bridge').EnvConfigInterface;
|
|
59
62
|
// ... 更多映射
|
|
@@ -100,7 +103,8 @@ export class UserService extends UserAuthService<UserInfo> {
|
|
|
100
103
|
@inject(RouteService) protected routerService: RouteService,
|
|
101
104
|
@inject(UserApi) userApi: UserAuthApiInterface<UserInfo>,
|
|
102
105
|
@inject(IOCIdentifier.AppConfig) appConfig: AppConfig,
|
|
103
|
-
@inject(IOCIdentifier.LocalStorageEncrypt)
|
|
106
|
+
@inject(IOCIdentifier.LocalStorageEncrypt)
|
|
107
|
+
storage: SyncStorageInterface<string, string>
|
|
104
108
|
) {
|
|
105
109
|
super(userApi, {
|
|
106
110
|
userStorage: {
|
|
@@ -121,9 +125,9 @@ export class UserService extends UserAuthService<UserInfo> {
|
|
|
121
125
|
```tsx
|
|
122
126
|
// 在启动器中注册服务
|
|
123
127
|
bootstrap.use([
|
|
124
|
-
IOC(UserService),
|
|
125
|
-
IOC(I18nService),
|
|
126
|
-
new UserApiBootstarp()
|
|
128
|
+
IOC(UserService), // 用户服务
|
|
129
|
+
IOC(I18nService), // 国际化服务
|
|
130
|
+
new UserApiBootstarp() // API 配置
|
|
127
131
|
]);
|
|
128
132
|
```
|
|
129
133
|
|
|
@@ -137,11 +141,11 @@ export const RegisterGlobals: IOCRegister = {
|
|
|
137
141
|
register(container, _, options): void {
|
|
138
142
|
// 注册应用配置
|
|
139
143
|
container.bind(IOCIdentifier.AppConfig, options!.appConfig);
|
|
140
|
-
|
|
144
|
+
|
|
141
145
|
// 注册日志服务
|
|
142
146
|
container.bind(Logger, logger);
|
|
143
147
|
container.bind(IOCIdentifier.Logger, logger);
|
|
144
|
-
|
|
148
|
+
|
|
145
149
|
// 注册存储服务
|
|
146
150
|
container.bind(IOCIdentifier.LocalStorage, localStorage);
|
|
147
151
|
container.bind(IOCIdentifier.LocalStorageEncrypt, localStorageEncrypt);
|
|
@@ -162,22 +166,28 @@ export const RegisterCommon: IOCRegister = {
|
|
|
162
166
|
const feApiToken = new TokenStorage(AppConfig.userTokenStorageKey, {
|
|
163
167
|
storage: container.get(IOCIdentifier.LocalStorageEncrypt)
|
|
164
168
|
});
|
|
165
|
-
|
|
169
|
+
|
|
166
170
|
container.bind(IOCIdentifier.FeApiToken, feApiToken);
|
|
167
171
|
container.bind(IOCIdentifier.FeApiCommonPlugin, feApiRequestCommonPlugin);
|
|
168
|
-
|
|
172
|
+
|
|
169
173
|
// 注册主题服务
|
|
170
|
-
container.bind(
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
174
|
+
container.bind(
|
|
175
|
+
ThemeService,
|
|
176
|
+
new ThemeService({
|
|
177
|
+
...themeConfig,
|
|
178
|
+
storage: localStorage
|
|
179
|
+
})
|
|
180
|
+
);
|
|
181
|
+
|
|
175
182
|
// 注册路由服务
|
|
176
|
-
container.bind(
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
183
|
+
container.bind(
|
|
184
|
+
RouteService,
|
|
185
|
+
new RouteService({
|
|
186
|
+
routes: baseRoutes,
|
|
187
|
+
logger
|
|
188
|
+
})
|
|
189
|
+
);
|
|
190
|
+
|
|
181
191
|
// 注册国际化服务
|
|
182
192
|
container.bind(I18nService, new I18nService(options!.pathname));
|
|
183
193
|
}
|
|
@@ -189,7 +199,10 @@ export const RegisterCommon: IOCRegister = {
|
|
|
189
199
|
```tsx
|
|
190
200
|
// core/registers/RegisterControllers.ts
|
|
191
201
|
export class RegisterControllers implements IOCRegister {
|
|
192
|
-
register(
|
|
202
|
+
register(
|
|
203
|
+
container: IOCContainer,
|
|
204
|
+
_: IOCManagerInterface<IOCContainer>
|
|
205
|
+
): void {
|
|
193
206
|
// 注册控制器
|
|
194
207
|
const jsonStorageController = new JSONStorageController(localStorage);
|
|
195
208
|
container.bind(JSONStorageController, jsonStorageController);
|
|
@@ -214,7 +227,8 @@ export class UserService extends UserAuthService<UserInfo> {
|
|
|
214
227
|
@inject(RouteService) protected routerService: RouteService,
|
|
215
228
|
@inject(UserApi) userApi: UserAuthApiInterface<UserInfo>,
|
|
216
229
|
@inject(IOCIdentifier.AppConfig) appConfig: AppConfig,
|
|
217
|
-
@inject(IOCIdentifier.LocalStorageEncrypt)
|
|
230
|
+
@inject(IOCIdentifier.LocalStorageEncrypt)
|
|
231
|
+
storage: SyncStorageInterface<string, string>
|
|
218
232
|
) {
|
|
219
233
|
super(userApi, {
|
|
220
234
|
userStorage: {
|
|
@@ -290,7 +304,6 @@ export class UserService {
|
|
|
290
304
|
@inject(UserApi) private userApi: UserApi,
|
|
291
305
|
@inject(IOCIdentifier.AppConfig) private appConfig: AppConfig
|
|
292
306
|
) {}
|
|
293
|
-
|
|
294
307
|
async getUserInfo(): Promise<UserInfo> {
|
|
295
308
|
return this.userApi.getUserInfo();
|
|
296
309
|
}
|
|
@@ -305,7 +318,6 @@ export class BadService {
|
|
|
305
318
|
@inject(ThemeService) private themeService: ThemeService,
|
|
306
319
|
@inject(I18nService) private i18nService: I18nService
|
|
307
320
|
) {}
|
|
308
|
-
|
|
309
321
|
// 一个服务做了太多事情
|
|
310
322
|
async handleUserAction(): Promise<void> {
|
|
311
323
|
// 处理用户逻辑
|
|
@@ -342,9 +354,7 @@ export class SomeService {
|
|
|
342
354
|
```tsx
|
|
343
355
|
@injectable()
|
|
344
356
|
export class SafeService {
|
|
345
|
-
constructor(
|
|
346
|
-
@inject(IOCIdentifier.Logger) private logger: LoggerInterface
|
|
347
|
-
) {}
|
|
357
|
+
constructor(@inject(IOCIdentifier.Logger) private logger: LoggerInterface) {}
|
|
348
358
|
|
|
349
359
|
async doSomething(): Promise<void> {
|
|
350
360
|
try {
|
|
@@ -381,12 +391,14 @@ describe('UserService', () => {
|
|
|
381
391
|
|
|
382
392
|
beforeEach(() => {
|
|
383
393
|
container = new Container();
|
|
384
|
-
|
|
394
|
+
|
|
385
395
|
// 注册测试依赖
|
|
386
396
|
container.bind('UserApiInterface').toConstantValue(mockUserApi);
|
|
387
397
|
container.bind(IOCIdentifier.AppConfig).toConstantValue(mockAppConfig);
|
|
388
|
-
container
|
|
389
|
-
|
|
398
|
+
container
|
|
399
|
+
.bind(IOCIdentifier.LocalStorageEncrypt)
|
|
400
|
+
.toConstantValue(mockStorage);
|
|
401
|
+
|
|
390
402
|
userService = container.get(UserService);
|
|
391
403
|
});
|
|
392
404
|
|
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
# 项目结构说明
|
|
2
|
+
|
|
3
|
+
## 目录结构
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
src/
|
|
7
|
+
├── base/ # 基础功能实现
|
|
8
|
+
│ ├── apis/ # API 接口定义和实现
|
|
9
|
+
│ │ └── userApi/ # 用户相关 API
|
|
10
|
+
│ ├── cases/ # 业务场景实现
|
|
11
|
+
│ │ ├── AppConfig.ts # 应用配置
|
|
12
|
+
│ │ ├── RouterLoader.ts # 路由加载器
|
|
13
|
+
│ │ └── I18nKeyErrorPlugin.ts # 国际化错误处理
|
|
14
|
+
│ ├── services/ # 核心服务实现
|
|
15
|
+
│ │ ├── UserService.ts # 用户服务
|
|
16
|
+
│ │ ├── RouteService.ts # 路由服务
|
|
17
|
+
│ │ └── I18nService.ts # 国际化服务
|
|
18
|
+
│ └── types/ # 类型定义
|
|
19
|
+
├── core/ # 核心功能
|
|
20
|
+
│ ├── bootstraps/ # 启动相关
|
|
21
|
+
│ │ └── BootstrapApp.ts # 应用启动器
|
|
22
|
+
│ ├── registers/ # 注册器
|
|
23
|
+
│ │ ├── RegisterCommon.ts # 通用服务注册
|
|
24
|
+
│ │ └── RegisterGlobals.ts # 全局变量注册
|
|
25
|
+
│ └── IOC.ts # IOC 容器
|
|
26
|
+
├── pages/ # 页面组件
|
|
27
|
+
│ ├── auth/ # 认证相关页面
|
|
28
|
+
│ │ ├── LoginPage.tsx # 登录页面
|
|
29
|
+
│ │ └── RegisterPage.tsx # 注册页面
|
|
30
|
+
│ └── base/ # 基础页面
|
|
31
|
+
│ ├── HomePage.tsx # 首页
|
|
32
|
+
│ └── ErrorPage.tsx # 错误页面
|
|
33
|
+
├── styles/ # 样式文件
|
|
34
|
+
│ └── css/
|
|
35
|
+
│ ├── themes/ # 主题相关
|
|
36
|
+
│ └── antd-themes/ # Ant Design 主题
|
|
37
|
+
├── uikit/ # UI 组件库
|
|
38
|
+
│ ├── components/ # 通用组件
|
|
39
|
+
│ ├── contexts/ # React Context
|
|
40
|
+
│ ├── hooks/ # 自定义 Hooks
|
|
41
|
+
│ └── providers/ # 提供者组件
|
|
42
|
+
└── App.tsx # 应用入口
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## 已实现功能
|
|
46
|
+
|
|
47
|
+
### 1. 用户认证系统
|
|
48
|
+
|
|
49
|
+
#### 登录功能
|
|
50
|
+
|
|
51
|
+
- 支持邮箱密码登录
|
|
52
|
+
- 记住登录状态
|
|
53
|
+
- 登录状态持久化
|
|
54
|
+
- 登录错误处理
|
|
55
|
+
- 支持第三方登录(预留接口)
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
// 登录服务示例
|
|
59
|
+
class UserService extends UserAuthService<UserInfo> {
|
|
60
|
+
async login(credentials: LoginFormData) {
|
|
61
|
+
// 登录实现
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async logout() {
|
|
65
|
+
// 登出实现
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
#### 注册功能
|
|
71
|
+
|
|
72
|
+
- 用户注册表单
|
|
73
|
+
- 表单验证
|
|
74
|
+
- 密码强度检查
|
|
75
|
+
- 服务条款同意
|
|
76
|
+
- 注册成功跳转
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
// 注册功能示例
|
|
80
|
+
async register(params: RegisterFormData) {
|
|
81
|
+
const response = await this.api.register(params);
|
|
82
|
+
// 处理注册逻辑
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### 2. 路由系统
|
|
87
|
+
|
|
88
|
+
#### 特性
|
|
89
|
+
|
|
90
|
+
- 配置式路由
|
|
91
|
+
- 路由级别代码分割
|
|
92
|
+
- 路由守卫
|
|
93
|
+
- 路由元信息
|
|
94
|
+
- 多语言路由支持
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
// 路由配置示例
|
|
98
|
+
export const baseRoutes: RouteConfigValue[] = [
|
|
99
|
+
{
|
|
100
|
+
path: '/:lng',
|
|
101
|
+
element: 'base/Layout',
|
|
102
|
+
meta: {
|
|
103
|
+
category: 'main'
|
|
104
|
+
},
|
|
105
|
+
children: [...]
|
|
106
|
+
}
|
|
107
|
+
];
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### 3. 国际化系统
|
|
111
|
+
|
|
112
|
+
#### 特性
|
|
113
|
+
|
|
114
|
+
- 支持中英文切换
|
|
115
|
+
- 路由级别的语言切换
|
|
116
|
+
- 基于 TypeScript 注释的翻译生成
|
|
117
|
+
- 动态加载语言包
|
|
118
|
+
- 完整的类型支持
|
|
119
|
+
|
|
120
|
+
### 4. 主题系统
|
|
121
|
+
|
|
122
|
+
#### 特性
|
|
123
|
+
|
|
124
|
+
- 支持多主题切换
|
|
125
|
+
- CSS 变量驱动
|
|
126
|
+
- Tailwind CSS 集成
|
|
127
|
+
- Ant Design 主题定制
|
|
128
|
+
- 响应式设计
|
|
129
|
+
|
|
130
|
+
### 5. 状态管理
|
|
131
|
+
|
|
132
|
+
#### 特性
|
|
133
|
+
|
|
134
|
+
- 基于 Store 的状态管理
|
|
135
|
+
- 响应式数据流
|
|
136
|
+
- 状态持久化
|
|
137
|
+
- 状态分片
|
|
138
|
+
- 完整的类型支持
|
|
139
|
+
|
|
140
|
+
### 6. UI 组件库
|
|
141
|
+
|
|
142
|
+
#### 已实现组件
|
|
143
|
+
|
|
144
|
+
- 布局组件
|
|
145
|
+
- BaseLayout:基础布局
|
|
146
|
+
- AuthLayout:认证页面布局
|
|
147
|
+
- 通用组件
|
|
148
|
+
- ThemeSwitcher:主题切换器
|
|
149
|
+
- LanguageSwitcher:语言切换器
|
|
150
|
+
- Loading:加载状态
|
|
151
|
+
- 表单组件
|
|
152
|
+
- LoginForm:登录表单
|
|
153
|
+
- RegisterForm:注册表单
|
|
154
|
+
|
|
155
|
+
### 7. 工具集成
|
|
156
|
+
|
|
157
|
+
#### 开发工具
|
|
158
|
+
|
|
159
|
+
- TypeScript 支持
|
|
160
|
+
- ESLint 配置
|
|
161
|
+
- Prettier 格式化
|
|
162
|
+
- Jest 测试框架
|
|
163
|
+
- Vite 构建工具
|
|
164
|
+
|
|
165
|
+
#### 辅助功能
|
|
166
|
+
|
|
167
|
+
- 路由自动生成
|
|
168
|
+
- API 请求封装
|
|
169
|
+
- 错误处理
|
|
170
|
+
- 日志系统
|
|
171
|
+
- 缓存管理
|
|
172
|
+
|
|
173
|
+
### 8. 安全特性
|
|
174
|
+
|
|
175
|
+
#### 已实现
|
|
176
|
+
|
|
177
|
+
- CSRF 防护
|
|
178
|
+
- XSS 防护
|
|
179
|
+
- 请求加密
|
|
180
|
+
- 数据脱敏
|
|
181
|
+
- 权限控制
|
|
182
|
+
|
|
183
|
+
## 扩展点
|
|
184
|
+
|
|
185
|
+
### 1. 认证系统扩展
|
|
186
|
+
|
|
187
|
+
- 添加更多第三方登录
|
|
188
|
+
- 实现手机号登录
|
|
189
|
+
- 添加双因素认证
|
|
190
|
+
- 实现密码重置
|
|
191
|
+
|
|
192
|
+
### 2. UI 组件扩展
|
|
193
|
+
|
|
194
|
+
- 添加更多业务组件
|
|
195
|
+
- 扩展主题系统
|
|
196
|
+
- 添加动画效果
|
|
197
|
+
- 优化移动端适配
|
|
198
|
+
|
|
199
|
+
### 3. 功能扩展
|
|
200
|
+
|
|
201
|
+
- 添加文件上传
|
|
202
|
+
- 实现实时通讯
|
|
203
|
+
- 添加数据可视化
|
|
204
|
+
- 实现离线支持
|
|
205
|
+
|
|
206
|
+
## 项目依赖说明
|
|
207
|
+
|
|
208
|
+
### 核心依赖
|
|
209
|
+
|
|
210
|
+
#### React 相关
|
|
211
|
+
|
|
212
|
+
- **react** (^18.3.1)
|
|
213
|
+
- 核心框架
|
|
214
|
+
- 使用最新的 React 18 特性
|
|
215
|
+
- 支持并发模式和 Suspense
|
|
216
|
+
|
|
217
|
+
- **react-dom** (^18.3.1)
|
|
218
|
+
- React 的 DOM 渲染器
|
|
219
|
+
- 用于 Web 平台渲染
|
|
220
|
+
|
|
221
|
+
- **react-router-dom** (^7.1.5)
|
|
222
|
+
- 路由管理
|
|
223
|
+
- 使用最新的数据路由功能
|
|
224
|
+
- 支持嵌套路由和路由守卫
|
|
225
|
+
|
|
226
|
+
#### 状态管理
|
|
227
|
+
|
|
228
|
+
- **@qlover/slice-store-react** (^1.0.8)
|
|
229
|
+
- 状态管理解决方案
|
|
230
|
+
- 基于发布订阅模式
|
|
231
|
+
- 支持状态分片和响应式更新
|
|
232
|
+
|
|
233
|
+
- **@qlover/corekit-bridge**
|
|
234
|
+
- 核心功能桥接层
|
|
235
|
+
- 提供状态管理与 UI 的连接
|
|
236
|
+
- 实现依赖注入和服务管理
|
|
237
|
+
|
|
238
|
+
#### UI 框架
|
|
239
|
+
|
|
240
|
+
- **antd** (^5.25.3)
|
|
241
|
+
- UI 组件库
|
|
242
|
+
- 使用 v5 版本
|
|
243
|
+
- 支持主题定制和 CSS-in-JS
|
|
244
|
+
|
|
245
|
+
- **@brain-toolkit/antd-theme-override** (^0.0.3)
|
|
246
|
+
- Ant Design 主题覆盖工具
|
|
247
|
+
- 实现主题变量的动态切换
|
|
248
|
+
- 支持自定义主题配置
|
|
249
|
+
|
|
250
|
+
#### 样式工具
|
|
251
|
+
|
|
252
|
+
- **tailwindcss** (^4.1.8)
|
|
253
|
+
- 原子化 CSS 框架
|
|
254
|
+
- 用于快速构建响应式界面
|
|
255
|
+
- 与主题系统集成
|
|
256
|
+
|
|
257
|
+
- **clsx** (^2.1.1)
|
|
258
|
+
- 类名管理工具
|
|
259
|
+
- 用于条件性类名拼接
|
|
260
|
+
- 提供类型安全的 API
|
|
261
|
+
|
|
262
|
+
#### 国际化
|
|
263
|
+
|
|
264
|
+
- **i18next** (^24.2.0)
|
|
265
|
+
- 国际化框架
|
|
266
|
+
- 支持动态语言切换
|
|
267
|
+
- 提供完整的翻译管理
|
|
268
|
+
|
|
269
|
+
- **i18next-browser-languagedetector** (^8.0.2)
|
|
270
|
+
- 浏览器语言检测
|
|
271
|
+
- 自动检测用户语言偏好
|
|
272
|
+
- 支持多种检测策略
|
|
273
|
+
|
|
274
|
+
- **i18next-http-backend** (^3.0.1)
|
|
275
|
+
- 翻译资源加载器
|
|
276
|
+
- 支持动态加载翻译文件
|
|
277
|
+
- 实现按需加载
|
|
278
|
+
|
|
279
|
+
#### 依赖注入
|
|
280
|
+
|
|
281
|
+
- **inversify** (^7.1.0)
|
|
282
|
+
- IoC 容器实现
|
|
283
|
+
- 用于依赖注入
|
|
284
|
+
- 提供服务管理和注册
|
|
285
|
+
|
|
286
|
+
- **reflect-metadata** (^0.2.2)
|
|
287
|
+
- 元数据反射支持
|
|
288
|
+
- 用于装饰器实现
|
|
289
|
+
- 支持依赖注入的类型信息
|
|
290
|
+
|
|
291
|
+
### 开发依赖
|
|
292
|
+
|
|
293
|
+
#### 构建工具
|
|
294
|
+
|
|
295
|
+
- **vite** (^6.3.5)
|
|
296
|
+
- 现代构建工具
|
|
297
|
+
- 提供快速的开发服务器
|
|
298
|
+
- 支持 ESM 和资源优化
|
|
299
|
+
|
|
300
|
+
- **@vitejs/plugin-react** (^4.4.1)
|
|
301
|
+
- React 插件
|
|
302
|
+
- 提供 React 特定优化
|
|
303
|
+
- 支持 Fast Refresh
|
|
304
|
+
|
|
305
|
+
#### 类型支持
|
|
306
|
+
|
|
307
|
+
- **typescript** (^5.6.3)
|
|
308
|
+
- JavaScript 超集
|
|
309
|
+
- 提供类型检查
|
|
310
|
+
- 增强开发体验
|
|
311
|
+
|
|
312
|
+
#### 代码质量
|
|
313
|
+
|
|
314
|
+
- **eslint** (^9.15.0)
|
|
315
|
+
- 代码检查工具
|
|
316
|
+
- 确保代码质量
|
|
317
|
+
- 支持自定义规则
|
|
318
|
+
|
|
319
|
+
- **prettier** (^3.5.3)
|
|
320
|
+
- 代码格式化工具
|
|
321
|
+
- 统一代码风格
|
|
322
|
+
- 与 ESLint 集成
|
|
323
|
+
|
|
324
|
+
#### 测试工具
|
|
325
|
+
|
|
326
|
+
- **vitest** (^3.0.5)
|
|
327
|
+
- 单元测试框架
|
|
328
|
+
- 与 Vite 深度集成
|
|
329
|
+
- 提供快速的测试执行
|
|
330
|
+
|
|
331
|
+
### 自定义工具包
|
|
332
|
+
|
|
333
|
+
#### 日志系统
|
|
334
|
+
|
|
335
|
+
- **@qlover/logger** (^0.1.1)
|
|
336
|
+
- 统一的日志管理
|
|
337
|
+
- 支持不同级别的日志
|
|
338
|
+
- 提供格式化输出
|
|
339
|
+
|
|
340
|
+
#### 环境配置
|
|
341
|
+
|
|
342
|
+
- **@qlover/env-loader**
|
|
343
|
+
- 环境变量加载
|
|
344
|
+
- 支持多环境配置
|
|
345
|
+
- 类型安全的配置访问
|
|
346
|
+
|
|
347
|
+
#### 开发工具
|
|
348
|
+
|
|
349
|
+
- **@qlover/fe-scripts**
|
|
350
|
+
- 开发脚本集合
|
|
351
|
+
- 提供常用的开发命令
|
|
352
|
+
- 简化开发流程
|
|
353
|
+
|
|
354
|
+
#### 代码规范
|
|
355
|
+
|
|
356
|
+
- **@qlover/fe-standard** (^0.0.4)
|
|
357
|
+
- 统一的代码规范
|
|
358
|
+
- ESLint 规则集
|
|
359
|
+
- TypeScript 配置
|
|
360
|
+
|
|
361
|
+
## 依赖版本管理
|
|
362
|
+
|
|
363
|
+
### 版本更新策略
|
|
364
|
+
|
|
365
|
+
- 核心依赖:谨慎更新,需要完整测试
|
|
366
|
+
- UI 框架:跟随官方 LTS 版本
|
|
367
|
+
- 工具依赖:定期更新到最新版本
|
|
368
|
+
- 自定义包:使用 latest 标签跟踪最新版本
|
|
369
|
+
|
|
370
|
+
### 依赖检查
|
|
371
|
+
|
|
372
|
+
```bash
|
|
373
|
+
# 检查过期依赖
|
|
374
|
+
npm outdated
|
|
375
|
+
|
|
376
|
+
# 更新依赖
|
|
377
|
+
npm update
|
|
378
|
+
|
|
379
|
+
# 安装特定版本
|
|
380
|
+
npm install package@version
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
## 开发指南
|
|
384
|
+
|
|
385
|
+
### 1. 开始开发
|
|
386
|
+
|
|
387
|
+
```bash
|
|
388
|
+
# 安装依赖
|
|
389
|
+
npm install
|
|
390
|
+
|
|
391
|
+
# 启动开发服务器
|
|
392
|
+
npm run dev
|
|
393
|
+
|
|
394
|
+
# 构建生产版本
|
|
395
|
+
npm run build
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
### 2. 添加新功能
|
|
399
|
+
|
|
400
|
+
1. 在 `src/base/services` 添加服务
|
|
401
|
+
2. 在 `src/base/apis` 添加 API
|
|
402
|
+
3. 在 `src/pages` 添加页面组件
|
|
403
|
+
4. 在 `config/app.router.ts` 添加路由配置
|
|
404
|
+
5. 在 `src/uikit/components` 添加通用组件
|
|
405
|
+
|
|
406
|
+
### 3. 测试
|
|
407
|
+
|
|
408
|
+
```bash
|
|
409
|
+
# 运行所有测试
|
|
410
|
+
npm test
|
|
411
|
+
|
|
412
|
+
# 运行特定测试
|
|
413
|
+
npm test <test-file>
|
|
414
|
+
|
|
415
|
+
# 更新快照
|
|
416
|
+
npm test -- -u
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
## 注意事项
|
|
420
|
+
|
|
421
|
+
1. **代码组织**
|
|
422
|
+
- 遵循目录结构规范
|
|
423
|
+
- 使用适当的文件命名
|
|
424
|
+
- 保持代码模块化
|
|
425
|
+
|
|
426
|
+
2. **性能考虑**
|
|
427
|
+
- 合理使用代码分割
|
|
428
|
+
- 优化组件渲染
|
|
429
|
+
- 控制依赖大小
|
|
430
|
+
|
|
431
|
+
3. **安全性**
|
|
432
|
+
- 遵循安全最佳实践
|
|
433
|
+
- 正确处理用户数据
|
|
434
|
+
- 保护敏感信息
|