@skyfox2000/microbase 1.2.1 → 1.3.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/README.md CHANGED
@@ -1,16 +1,322 @@
1
- # 微前端通用功能与数据类型定义
1
+ # 微前端基础类型库 (@skyfox2000/microbase)
2
2
 
3
- ## 项目简介
3
+ ## 项目概述
4
4
 
5
- 这是一个基础定义库,需要配合 `@skyfox2000/webbase` 使用
5
+ 这是一个专为微前端架构设计的基础类型库,提供了微前端应用间通信、数据类型定义、路由管理和模块加载等核心功能。该库是微前端生态系统的基础组件,为主应用和子应用之间的协作提供标准化的接口和数据结构。
6
6
 
7
- ## 安装方式
8
- ```shell
7
+ ## 核心特性
8
+
9
+ ### 🔗 微前端通信
10
+ - **主子应用通信**:提供标准化的主应用与子应用通信接口
11
+ - **数据传递**:支持用户信息、应用配置、路由状态等数据在应用间传递
12
+ - **事件机制**:支持应用间事件监听和触发
13
+ - **环境检测**:自动检测当前运行环境(独立应用/微应用/基座应用)
14
+
15
+ ### 📋 类型定义体系
16
+ - **应用信息类型**:完整的应用元数据类型定义
17
+ - **用户信息类型**:用户认证和权限相关类型
18
+ - **主机信息类型**:环境配置和服务地址类型
19
+ - **设置信息类型**:前端配置和偏好设置类型
20
+
21
+ ### 🛠 工具函数集合
22
+ - **数据处理**:参数组合、数据转换等工具函数
23
+ - **环境管理**:环境变量统一管理和配置
24
+ - **路由加载**:动态路由加载和管理
25
+ - **模块加载**:支持动态模块加载和组件注册
26
+
27
+ ## 安装使用
28
+
29
+ ### 安装方式
30
+ ```bash
9
31
  npm install -S @skyfox2000/microbase
10
32
  ```
11
33
 
12
- ## 功能清单
34
+ ### 基本使用
35
+ ```typescript
36
+ import {
37
+ isMicroApp,
38
+ initMainAppData,
39
+ mainAppApis,
40
+ AppInfo,
41
+ UserInfo
42
+ } from '@skyfox2000/microbase';
43
+
44
+ // 检测是否在微应用环境中运行
45
+ if (isMicroApp()) {
46
+ // 初始化主应用数据
47
+ initMainAppData();
48
+
49
+ // 使用主应用提供的API
50
+ if (mainAppApis.value?.getUserInfo) {
51
+ const userInfo = mainAppApis.value.getUserInfo();
52
+ console.log('当前用户:', userInfo);
53
+ }
54
+ }
55
+ ```
56
+
57
+ ## API 文档
58
+
59
+ ### 环境检测函数
60
+
61
+ #### `isMicroApp(): boolean`
62
+ 检测当前应用是否运行在微前端环境中
63
+ ```typescript
64
+ if (isMicroApp()) {
65
+ console.log('运行在微前端环境');
66
+ }
67
+ ```
68
+
69
+ #### `isBaseMicroApp(): boolean`
70
+ 检测当前应用是否为微前端基座应用
71
+ ```typescript
72
+ if (isBaseMicroApp()) {
73
+ console.log('当前是基座应用');
74
+ }
75
+ ```
76
+
77
+ ### 主应用通信
78
+
79
+ #### `initMainAppData(): void`
80
+ 初始化主应用数据,建立与主应用的通信连接
81
+ ```typescript
82
+ // 在微应用启动时调用
83
+ initMainAppData();
84
+ ```
85
+
86
+ #### `mainAppApis: Ref<MainOpenApis | undefined>`
87
+ 主应用开放的API接口集合
88
+ ```typescript
89
+ // 获取用户信息
90
+ const userInfo = mainAppApis.value?.getUserInfo?.();
91
+
92
+ // 路由跳转
93
+ mainAppApis.value?.mainAppPush?.('/target-path');
94
+
95
+ // 用户登录
96
+ await mainAppApis.value?.userLogin?.(loginInfo);
97
+ ```
98
+
99
+ #### `mainAppEvents: Ref<MainOpenEvents | undefined>`
100
+ 主应用开放的事件监听接口
101
+ ```typescript
102
+ // 监听设置变更事件
103
+ mainAppEvents.value?.onSettingChanged?.();
104
+ ```
105
+
106
+ ### 环境配置
107
+
108
+ #### `EnvConfig: { [key: string]: string }`
109
+ 统一的环境变量配置对象
110
+
111
+ #### `initEnv(metaEnv: ImportMetaEnv): void`
112
+ 初始化环境变量配置
113
+ ```typescript
114
+ import { initEnv } from '@skyfox2000/microbase';
115
+
116
+ // 在应用启动时初始化环境变量
117
+ initEnv(import.meta.env);
118
+ ```
119
+
120
+ ### 数据处理工具
121
+
122
+ #### `combineParams(params: any): any`
123
+ 参数组合和处理工具函数
124
+ ```typescript
125
+ import { combineParams } from '@skyfox2000/microbase';
126
+
127
+ const combinedParams = combineParams({
128
+ param1: 'value1',
129
+ param2: 'value2'
130
+ });
131
+ ```
132
+
133
+ ### 路由管理
134
+
135
+ #### `LoaderRouter`
136
+ 动态路由加载器,支持路由的动态注册和管理
137
+ ```typescript
138
+ import { LoaderRouter } from '@skyfox2000/microbase';
139
+
140
+ // 使用路由加载器
141
+ const router = new LoaderRouter(routeConfig);
142
+ ```
143
+
144
+ ### 模块加载
145
+
146
+ #### 模块加载器函数
147
+ ```typescript
148
+ import {
149
+ loadModule,
150
+ initModuleLoader,
151
+ moduleAttrs,
152
+ moduleUrl,
153
+ moduleRecords,
154
+ moduleCom
155
+ } from '@skyfox2000/microbase';
13
156
 
14
- ## 功能使用说明
157
+ // 初始化模块加载器
158
+ initModuleLoader();
159
+
160
+ // 动态加载模块
161
+ await loadModule('module-name');
162
+ ```
163
+
164
+ ## 类型定义
165
+
166
+ ### AppInfo - 应用信息
167
+ ```typescript
168
+ interface AppInfo {
169
+ readonly Id: string; // 应用唯一标识
170
+ readonly Name: string; // 应用名称
171
+ readonly AppCode: string; // 应用编码(路由前缀)
172
+ readonly Version: string; // 版本号
173
+ readonly Icon: string; // 应用图标
174
+ readonly Source: AppSource; // 应用来源
175
+ readonly Action: AppAction; // 应用动作类型
176
+ readonly Host: string; // 应用加载地址
177
+ readonly Enabled: boolean | number; // 启用状态
178
+ Page?: string; // 默认页面
179
+ Default?: boolean; // 是否默认应用
180
+ Description?: string; // 应用描述
181
+ }
182
+ ```
183
+
184
+ ### UserInfo - 用户信息
185
+ ```typescript
186
+ interface UserInfo {
187
+ readonly Id: string; // 用户ID
188
+ readonly Name: string; // 用户名称
189
+ readonly Code: string; // 用户编码
190
+ readonly TenantId: string | null; // 租户ID
191
+ readonly UserLevel: string; // 用户级别
192
+ readonly Roles?: string[]; // 角色列表
193
+ readonly Permissions?: string[]; // 权限列表
194
+ }
195
+ ```
196
+
197
+ ### LoginInfo - 登录信息
198
+ ```typescript
199
+ interface LoginInfo {
200
+ UserName: string; // 用户名
201
+ UserPass: string; // 密码
202
+ UserInfo?: UserInfo; // 用户信息
203
+ readonly token?: string; // 访问令牌
204
+ readonly refreshToken?: string; // 刷新令牌
205
+ }
206
+ ```
207
+
208
+ ### MainOpenApis - 主应用开放接口
209
+ ```typescript
210
+ interface MainOpenApis {
211
+ getHostInfo: () => HostInfo; // 获取主机信息
212
+ getAppInfo?: () => AppInfo; // 获取应用信息
213
+ userRegister?: () => void; // 用户注册
214
+ userLogin?: (loginInfo: LoginInfo) => Promise<ApiResponse<LoginInfo> | void>; // 用户登录
215
+ userLogout?: () => Promise<ApiResponse<any> | void>; // 用户登出
216
+ getToken?: () => string; // 获取授权令牌
217
+ getUserInfo?: () => UserInfo; // 获取用户信息
218
+ getSettingInfo?: () => SettingInfo; // 获取设置信息
219
+ mainAppPush?: (subPath: string) => void; // 路由跳转
220
+ }
221
+ ```
222
+
223
+ ## 枚举类型
224
+
225
+ ### AppSource - 应用来源
226
+ ```typescript
227
+ enum AppSource {
228
+ Market = "Market", // 从市场安装
229
+ Manual = "Manual" // 手动输入
230
+ }
231
+ ```
232
+
233
+ ### AppAction - 应用动作
234
+ ```typescript
235
+ enum AppAction {
236
+ App = "App", // 应用模式加载
237
+ MenuApp = "MenuApp", // 托管应用模式加载
238
+ Link = "Link", // 链接方式打开
239
+ Iframe = "Iframe" // Iframe内嵌方式打开
240
+ }
241
+ ```
242
+
243
+ ## 依赖要求
244
+
245
+ ### 对等依赖 (Peer Dependencies)
246
+ - **Vue**: ^3.5.13 - Vue 3 框架
247
+ - **Vue Router**: ^4.5.0 - Vue 路由管理
248
+ - **@skyfox2000/fapi**: ^1.1.19 - API请求库
249
+ - **@micro-zoe/micro-app**: ^1.0.0-rc.18 - 微前端框架
250
+
251
+ ## 构建配置
252
+
253
+ 该库使用 Vite 进行构建,支持:
254
+ - **TypeScript**: 完整的类型支持
255
+ - **ES Module**: 现代化的模块格式
256
+ - **类型声明**: 自动生成 .d.ts 文件
257
+ - **外部化依赖**: 避免重复打包核心依赖
258
+
259
+ ## 使用场景
260
+
261
+ ### 1. 微前端主应用
262
+ ```typescript
263
+ // 在主应用中提供API给子应用
264
+ const mainApis: MainOpenApis = {
265
+ getHostInfo: () => hostInfo,
266
+ getUserInfo: () => currentUser,
267
+ mainAppPush: (path) => router.push(path)
268
+ };
269
+
270
+ // 传递给子应用
271
+ microApp.setData('child-app', { MainApis: mainApis });
272
+ ```
273
+
274
+ ### 2. 微前端子应用
275
+ ```typescript
276
+ // 在子应用中接收主应用数据
277
+ if (isMicroApp()) {
278
+ initMainAppData();
279
+
280
+ // 使用主应用提供的功能
281
+ const userInfo = mainAppApis.value?.getUserInfo?.();
282
+ if (userInfo) {
283
+ // 处理用户信息
284
+ }
285
+ }
286
+ ```
287
+
288
+ ### 3. 独立应用
289
+ ```typescript
290
+ // 在独立应用中也可以使用类型定义
291
+ import type { AppInfo, UserInfo } from '@skyfox2000/microbase';
292
+
293
+ const appConfig: AppInfo = {
294
+ Id: 'app-001',
295
+ Name: '我的应用',
296
+ AppCode: 'my-app',
297
+ // ... 其他配置
298
+ };
299
+ ```
300
+
301
+ ## 版本历史
302
+
303
+ - **v1.2.1**: 当前版本,完善的微前端通信和类型定义
304
+ - **v1.1.x**: 增加模块加载功能
305
+ - **v1.0.x**: 初始版本,基础类型定义
15
306
 
16
307
  ## 注意事项
308
+
309
+ 1. **依赖管理**: 确保项目中已安装所有对等依赖
310
+ 2. **环境检测**: 在使用微前端功能前,先进行环境检测
311
+ 3. **类型安全**: 充分利用 TypeScript 类型检查,避免运行时错误
312
+ 4. **版本兼容**: 注意与其他 @skyfox2000 系列库的版本兼容性
313
+
314
+ ## 技术支持
315
+
316
+ - **仓库地址**: GitHub - @skyfox2000/microbase
317
+ - **问题反馈**: 通过 GitHub Issues 提交问题
318
+ - **文档更新**: 随版本更新同步维护
319
+
320
+ ---
321
+
322
+ *该库是微前端生态系统的核心基础库,为构建大型企业级微前端应用提供坚实的技术基础。*
package/lib/index.d.ts CHANGED
@@ -457,19 +457,8 @@ export declare interface UserInfo {
457
457
  readonly TenantId: string | null;
458
458
  /**
459
459
  * 用户级别
460
- * - Super 超级管理员
461
- * - Admin 系统管理员
462
- * - User 用户
463
460
  */
464
461
  readonly UserLevel: string;
465
- /**
466
- * 角色列表
467
- */
468
- readonly Roles?: string[]
469
- /**
470
- * 权限列表
471
- */
472
- readonly Permissions?: string[];
473
462
  }
474
463
 
475
464
  export { }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyfox2000/microbase",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "description": "微前端通用功能与数据类型定义",
5
5
  "type": "module",
6
6
  "keywords": [],
@@ -23,7 +23,7 @@
23
23
  "preview": "vite preview"
24
24
  },
25
25
  "peerDependencies": {
26
- "@skyfox2000/fapi": "^1.1.19",
26
+ "@skyfox2000/fapi": "^1.3.0",
27
27
  "@micro-zoe/micro-app": "^1.0.0-rc.18",
28
28
  "vue": "^3.5.13",
29
29
  "vue-router": "^4.5.0"
@@ -20,19 +20,8 @@ export interface UserInfo {
20
20
  readonly TenantId: string | null;
21
21
  /**
22
22
  * 用户级别
23
- * - Super 超级管理员
24
- * - Admin 系统管理员
25
- * - User 用户
26
23
  */
27
24
  readonly UserLevel: string;
28
- /**
29
- * 角色列表
30
- */
31
- readonly Roles?: string[]
32
- /**
33
- * 权限列表
34
- */
35
- readonly Permissions?: string[];
36
25
  }
37
26
 
38
27
  /**