@skyfox2000/microbase 1.0.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 ADDED
@@ -0,0 +1,16 @@
1
+ # 〇克微前端通用功能与数据类型定义
2
+
3
+ ## 项目简介
4
+
5
+ 这是一个基础定义库,需要配合 `@skyfox2000/webbase` 使用
6
+
7
+ ## 安装方式
8
+ ```shell
9
+ npm install -S @skyfox2000/microbase
10
+ ```
11
+
12
+ ## 功能清单
13
+
14
+ ## 功能使用说明
15
+
16
+ ## 注意事项
@@ -0,0 +1,11 @@
1
+ import { defineComponent as r, unref as e, openBlock as t, createBlock as n, resolveDynamicComponent as m, normalizeProps as u, mergeProps as a, createCommentVNode as l } from "vue";
2
+ import { loadModule as p, LoaderRouter as c, moduleCom as o, moduleAttrs as d } from "../../microbase.es.js";
3
+ const k = /* @__PURE__ */ r({
4
+ __name: "index",
5
+ setup(i) {
6
+ return window.microApp || p(c.currentRoute.value.path), (s, _) => e(o) != null ? (t(), n(m(e(o)), u(a({ key: 0 }, e(d))), null, 16)) : l("", !0);
7
+ }
8
+ });
9
+ export {
10
+ k as default
11
+ };
package/lib/index.d.ts ADDED
@@ -0,0 +1,459 @@
1
+ import { ApiResponse } from '@skyfox2000/fapi';
2
+ import { Ref } from 'vue';
3
+ import { ReqParams } from '@skyfox2000/fapi';
4
+ import { Router } from 'vue-router';
5
+ import { RouteRecordRaw } from 'vue-router';
6
+
7
+ /**
8
+ * 应用动作: App | Open | Iframe
9
+ */
10
+ export declare enum AppAction {
11
+ /**
12
+ * 应用模式加载
13
+ */
14
+ "App" = "App",
15
+ /**
16
+ * 托管应用模式加载
17
+ * - 菜单托管,平台管理加载菜单
18
+ */
19
+ "MenuApp" = "MenuApp",
20
+ /**
21
+ * 链接,弹出窗口打开
22
+ */
23
+ "Link" = "Link",
24
+ /**
25
+ * Iframe内嵌方式打开
26
+ */
27
+ "Iframe" = "Iframe"
28
+ }
29
+
30
+ /**
31
+ * 应用信息
32
+ */
33
+ export declare interface AppInfo {
34
+ /**
35
+ * 主键
36
+ */
37
+ Id: string;
38
+ /**
39
+ * 名称
40
+ */
41
+ Name: string;
42
+ /**
43
+ * 唯一编码
44
+ * - 路由前缀地址
45
+ */
46
+ AppCode: string;
47
+ /**
48
+ * 版本号
49
+ */
50
+ Version: string;
51
+ /**
52
+ * 图标
53
+ */
54
+ Icon: string;
55
+ /**
56
+ * 来源: Market | Manual
57
+ */
58
+ Source: AppSource;
59
+ /**
60
+ * 动作: App | MenuApp | Open | Iframe
61
+ */
62
+ Action: AppAction;
63
+ /**
64
+ * 应用加载地址
65
+ * - http开头地址
66
+ * - SERVER_HOST配置
67
+ */
68
+ Host: string;
69
+ /**
70
+ * 默认页面
71
+ */
72
+ Page?: string;
73
+ /**
74
+ * 默认应用,如没设置,则使用第一个
75
+ */
76
+ Default?: boolean;
77
+ /**
78
+ * 描述
79
+ */
80
+ Description?: string;
81
+
82
+ /**
83
+ * 启用状态
84
+ * - 启用 true 1
85
+ * - 停用 false 0
86
+ */
87
+ Enabled: boolean | number;
88
+ [key: string]: any;
89
+ }
90
+
91
+ /**
92
+ * 应用来源: Market | Manual
93
+ */
94
+ export declare enum AppSource {
95
+ /**
96
+ * 从市场安装
97
+ */
98
+ "Market" = "Market",
99
+ /**
100
+ * 手动输入
101
+ */
102
+ "Manual" = "Manual"
103
+ }
104
+
105
+ /**
106
+ * 深度合并QOD参数
107
+ */
108
+ export declare const combineParams: (...args: ReqParams[]) => ReqParams;
109
+
110
+ /**
111
+ * 路由权限判断
112
+ * @param route 指定路由
113
+ * @param isLogin 是否已登录
114
+ * @param userRoles 用户角色
115
+ * @param userPermits 用户权限
116
+ * @returns 权限判断结果
117
+ */
118
+ export declare const hasPermission: (route: RouteRecord, isLogin: boolean, userRoles: string[], userPermits: string[]) => boolean;
119
+
120
+ /**
121
+ * 启动配置信息
122
+ * - 网站配置信息
123
+ * - 前端初始配置
124
+ */
125
+ export declare interface HostInfo {
126
+ /**
127
+ * 网站地址,配置码
128
+ */
129
+ Host: string;
130
+ /**
131
+ * 短名称
132
+ */
133
+ Title: string;
134
+ /**
135
+ * 网站全名称
136
+ */
137
+ FullTitle?: string;
138
+ /**
139
+ * Logo图标地址
140
+ */
141
+ LogoIcon?: string;
142
+ /**
143
+ * 登录页面地址
144
+ */
145
+ LoginUrl?: string;
146
+ /**
147
+ * 用户信息页面地址
148
+ */
149
+ UserSettingUrl?: string;
150
+ /**
151
+ * 服务商名称
152
+ */
153
+ Provider?: string;
154
+ /**
155
+ * 接口域名地址
156
+ */
157
+ API_HOST?: {
158
+ [key: string]: string;
159
+ } | null;
160
+ /**
161
+ * 网站服务器地址
162
+ */
163
+ SERVER_HOST?: Record<string, string>;
164
+ /**
165
+ * 扩展属性配置
166
+ */
167
+ ExtraPropLines?: Record<string, any>[];
168
+ /**
169
+ * 扩展属性
170
+ */
171
+ ExtraProps?: {
172
+ [key: string]: string;
173
+ };
174
+ [key: string]: any;
175
+ }
176
+
177
+ /**
178
+ * 从页面加载处获取接口
179
+ */
180
+ export declare const initMainAppData: () => void;
181
+
182
+ /**
183
+ * 初始化微模块加载
184
+ * @param modules 微模块列表
185
+ */
186
+ export declare const initModuleLoader: (modules: Record<string, () => Promise<unknown>>) => void;
187
+
188
+ /**
189
+ * 是否微服务基座应用
190
+ * @returns
191
+ */
192
+ export declare const isBaseMicroApp: () => boolean;
193
+
194
+ /**
195
+ * 是否微服务运行环境
196
+ * @returns
197
+ */
198
+ export declare const isMicroApp: () => boolean;
199
+
200
+ export declare const LoaderRouter: Router;
201
+
202
+ /**
203
+ * 加载微模块
204
+ * @param module 微模块地址
205
+ */
206
+ export declare const loadModule: (page: string) => Promise<void>;
207
+
208
+ /**
209
+ * 登录信息与授权
210
+ */
211
+ export declare interface LoginInfo {
212
+ /**
213
+ * 用户名
214
+ */
215
+ UserName: string;
216
+ /**
217
+ * 密码
218
+ */
219
+ UserPass: string;
220
+ /**
221
+ * 登录返回的用户信息
222
+ */
223
+ UserInfo?: UserInfo;
224
+ /**
225
+ * 登录获取的授权token
226
+ */
227
+ token?: string;
228
+ /**
229
+ * 登录获取的刷新token
230
+ */
231
+ refreshToken?: string;
232
+ }
233
+
234
+ export declare const mainAppApis: Ref<MainOpenApis | undefined, MainOpenApis | undefined>;
235
+
236
+ /**
237
+ * 主应用初始化数据格式
238
+ */
239
+ export declare interface MainAppData {
240
+ /**
241
+ * 主应用开放接口
242
+ */
243
+ MainApis: MainOpenApis;
244
+ /**
245
+ * 主应用开放事件
246
+ */
247
+ MainEvents: MainOpenEvents;
248
+ /**
249
+ * 加载的页面地址
250
+ */
251
+ pageUrl: string;
252
+ }
253
+
254
+ export declare const mainAppEvents: Ref<MainOpenEvents | undefined, MainOpenEvents | undefined>;
255
+
256
+ /**
257
+ * 主应用开放接口
258
+ */
259
+ export declare interface MainOpenApis {
260
+ /**
261
+ * 获取HostInfo
262
+ */
263
+ getHostInfo: () => HostInfo;
264
+ /**
265
+ * 用户注册接口
266
+ */
267
+ userRegister?: () => void;
268
+ /**
269
+ * 用户登录接口
270
+ */
271
+ userLogin?: (loginInfo: LoginInfo) => Promise<ApiResponse<LoginInfo> | void>;
272
+ /**
273
+ * 获取授权码
274
+ * @returns 授权码
275
+ */
276
+ getToken: () => string;
277
+ /**
278
+ * 获取当前用户信息
279
+ */
280
+ getUserInfo: () => UserInfo;
281
+ /**
282
+ * 获取前端设置信息
283
+ */
284
+ getSettingInfo?: () => SettingInfo;
285
+ /**
286
+ * 子应用推送路由变更
287
+ */
288
+ mainAppPush?: (subPath: string) => void;
289
+ }
290
+
291
+ /**
292
+ * 主应用开放事件注册
293
+ */
294
+ export declare interface MainOpenEvents {
295
+ /**
296
+ * 前端设置信息变更
297
+ */
298
+ onSettingChanged?: () => void;
299
+ }
300
+
301
+ export declare const mainPageUrl: Ref<string | undefined, string | undefined>;
302
+
303
+ /**
304
+ * 菜单链接信息
305
+ */
306
+ export declare type MenuLink = {
307
+ /**
308
+ * 名称
309
+ */
310
+ name: string;
311
+ /**
312
+ * 图标
313
+ * icon可以是字符串路径或组件
314
+ */
315
+ icon: string;
316
+ /**
317
+ * 路径
318
+ */
319
+ path: string;
320
+ [key: string]: any;
321
+ };
322
+
323
+ /**
324
+ * 微模块属性配置
325
+ */
326
+ export declare const moduleAttrs: Ref<Record<string, any>, Record<string, any>>;
327
+
328
+ /**
329
+ * 当前微模块
330
+ */
331
+ export declare const moduleCom: Ref<any, any>;
332
+
333
+ /**
334
+ * 微模块列表
335
+ */
336
+ export declare const moduleRecords: Ref<Record<string, () => Promise<unknown>>, Record<string, () => Promise<unknown>>>;
337
+
338
+ /**
339
+ * 微模块地址
340
+ */
341
+ export declare const moduleUrl: Ref<string, string>;
342
+
343
+ /**
344
+ * 路由扩展信息
345
+ */
346
+ export declare type RouteMeta = {
347
+ /**
348
+ * 应用码,所属应用
349
+ */
350
+ code?: string | null;
351
+ /**
352
+ * 应用地址
353
+ */
354
+ host?: string | null;
355
+ /**
356
+ * 页面地址
357
+ */
358
+ page?: string | null;
359
+ /**
360
+ * 授权角色
361
+ */
362
+ roles?: string[];
363
+ /**
364
+ * 功能码
365
+ */
366
+ permission?: string;
367
+ };
368
+
369
+ /**
370
+ * 路由记录
371
+ */
372
+ export declare type RouteRecord = RouteRecordRaw & {
373
+ parent?: RouteRecord | null;
374
+ /**
375
+ * 路由图标
376
+ */
377
+ icon?: string;
378
+ /**
379
+ * 附加属性
380
+ */
381
+ meta?: RouteMeta;
382
+ /**
383
+ * 子路由信息
384
+ */
385
+ children?: RouteRecord[];
386
+ };
387
+
388
+ /**
389
+ * 表格行操作区位置
390
+ */
391
+ export declare enum RowOperate {
392
+ LEFT = 1,
393
+ RIGHT = 2
394
+ }
395
+
396
+ /**
397
+ * 前端个性化配置
398
+ */
399
+ export declare interface SettingInfo {
400
+ /**
401
+ * 全屏显示
402
+ */
403
+ readonly fullscreen: boolean;
404
+ /**
405
+ * 主菜单区折叠
406
+ */
407
+ readonly menuCollapse: boolean;
408
+ /**
409
+ * 表格行操作区位置
410
+ */
411
+ readonly rowOperate: RowOperate;
412
+ /**
413
+ * 使用语言
414
+ */
415
+ readonly language?: string;
416
+ /**
417
+ * 主题模式
418
+ */
419
+ readonly theme?: string;
420
+ /**
421
+ * 主题颜色
422
+ */
423
+ readonly themeColor?: string;
424
+ }
425
+
426
+ /**
427
+ * 用户信息
428
+ */
429
+ export declare interface UserInfo {
430
+ /**
431
+ * 主键
432
+ */
433
+ Id: string;
434
+ /**
435
+ * 名称
436
+ */
437
+ Name: string;
438
+ /**
439
+ * 用户码
440
+ */
441
+ Code: string;
442
+ /**
443
+ * 角色
444
+ */
445
+ Roles: string[];
446
+ /**
447
+ * 权限
448
+ */
449
+ Permissions: string[];
450
+ }
451
+
452
+ export { }
453
+
454
+
455
+ declare global {
456
+ interface Window {
457
+ microApp: EventCenterForMicroApp;
458
+ }
459
+ }
@@ -0,0 +1,109 @@
1
+ import { ref as o, markRaw as A, h as d } from "vue";
2
+ import { createRouter as M, createWebHashHistory as _ } from "vue-router";
3
+ var w = /* @__PURE__ */ ((e) => (e.Market = "Market", e.Manual = "Manual", e))(w || {}), D = /* @__PURE__ */ ((e) => (e.App = "App", e.MenuApp = "MenuApp", e.Link = "Link", e.Iframe = "Iframe", e))(D || {}), I = /* @__PURE__ */ ((e) => (e[e.LEFT = 1] = "LEFT", e[e.RIGHT = 2] = "RIGHT", e))(I || {});
4
+ const a = (e, t) => {
5
+ if (!(!t || !e))
6
+ for (const n in t)
7
+ n in e && typeof e[n] == "object" && typeof t[n] == "object" && !Array.isArray(t[n]) ? a(e[n], t[n]) : e[n] = c(t[n]);
8
+ }, c = (e) => {
9
+ if (e === null || typeof e != "object")
10
+ return e;
11
+ let t = Array.isArray(e) ? [] : {};
12
+ for (let n in e)
13
+ e.hasOwnProperty(n) && (t[n] = c(e[n]));
14
+ return t;
15
+ }, g = (...e) => {
16
+ const t = {};
17
+ for (const n of e)
18
+ n != null && n.Option && !t.Option && (t.Option = {}), a(t.Option, n == null ? void 0 : n.Option);
19
+ for (const n of e)
20
+ n != null && n.Query && !t.Query && (t.Query = {}), a(t.Query, n == null ? void 0 : n.Query);
21
+ for (const n of e)
22
+ t.Data = n != null && n.Data ? c(n.Data) : {};
23
+ return t;
24
+ }, C = () => !!window.__MICRO_APP_ENVIRONMENT__, N = () => !!window.__MICRO_APP_BASE_APPLICATION__, u = o(), O = o(), P = o(), U = () => {
25
+ const e = window.microApp.getData(
26
+ !0
27
+ );
28
+ u.value = e.MainApis, O.value = e.MainEvents, P.value = e.pageUrl;
29
+ }, k = [
30
+ {
31
+ path: "/:page(.*)",
32
+ name: "默认页面",
33
+ component: () => import("./assets/modules/index-yUrmSBei.js")
34
+ }
35
+ ], y = M({
36
+ history: _(void 0),
37
+ routes: k
38
+ }), Q = (e, t, n, l) => {
39
+ var f, p;
40
+ const r = ((f = e.meta) == null ? void 0 : f.roles) ?? [], i = (p = e.meta) == null ? void 0 : p.permission;
41
+ if (!t)
42
+ return r.length === 0 && !i;
43
+ if (t && (n.length > 0 || l.length > 0)) {
44
+ if (r.length === 0 && !i)
45
+ return !0;
46
+ if (r.length && !i)
47
+ return r.some((s) => n.includes(s));
48
+ if (!r.length && i)
49
+ return l.includes(i);
50
+ if (r.length && i)
51
+ return r.some((s) => n.includes(s)) && l.includes(i);
52
+ }
53
+ return !1;
54
+ };
55
+ y.afterEach((e) => {
56
+ if (u.value) {
57
+ const { mainAppPush: t } = u.value;
58
+ t && t(e.hash);
59
+ }
60
+ });
61
+ const H = o({}), h = o(""), v = o({}), m = o(null), E = async (e) => {
62
+ h.value = e, e.startsWith("/") && (e = e.substring(1));
63
+ const t = v.value[`./views/${e}.vue`];
64
+ if (t) {
65
+ const n = await t();
66
+ m.value = A(n.default), y.replace("/" + e);
67
+ } else
68
+ console.error("加载微模块" + e + "失败"), m.value = d(
69
+ "div",
70
+ {
71
+ style: {
72
+ display: "flex",
73
+ justifyContent: "center",
74
+ alignItems: "center",
75
+ height: "100vh",
76
+ // 使整个视口高度都被占满
77
+ flexDirection: "column"
78
+ // 使文本垂直居中
79
+ }
80
+ },
81
+ [d("div", "404 NOT FOUND")]
82
+ );
83
+ }, R = (e) => {
84
+ v.value = e, window.microApp && window.microApp.addDataListener(async (t) => {
85
+ if (t.pageUrl === h.value) return;
86
+ let n = t.pageUrl;
87
+ E(n);
88
+ }, !0);
89
+ };
90
+ export {
91
+ D as AppAction,
92
+ w as AppSource,
93
+ y as LoaderRouter,
94
+ I as RowOperate,
95
+ g as combineParams,
96
+ Q as hasPermission,
97
+ U as initMainAppData,
98
+ R as initModuleLoader,
99
+ N as isBaseMicroApp,
100
+ C as isMicroApp,
101
+ E as loadModule,
102
+ u as mainAppApis,
103
+ O as mainAppEvents,
104
+ P as mainPageUrl,
105
+ H as moduleAttrs,
106
+ m as moduleCom,
107
+ v as moduleRecords,
108
+ h as moduleUrl
109
+ };
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@skyfox2000/microbase",
3
+ "version": "1.0.0",
4
+ "description": "〇克微前端通用功能与数据类型定义",
5
+ "type": "module",
6
+ "keywords": [],
7
+ "author": "skyfox2000@github.com",
8
+ "license": "MIT",
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "module": "./lib/microbase.es.js",
13
+ "types": "./lib/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./lib/index.d.ts",
17
+ "default": "./lib/microbase.es.js"
18
+ }
19
+ },
20
+ "scripts": {
21
+ "dev": "vite",
22
+ "build": "vue-tsc -b && vite build",
23
+ "preview": "vite preview"
24
+ },
25
+ "dependencies": {
26
+ "@micro-zoe/micro-app": "1.0.0-rc.18",
27
+ "vue": "^3.5.13",
28
+ "vue-router": "^4.5.0"
29
+ },
30
+ "devDependencies": {
31
+ "@types/node": "^22.10.2",
32
+ "@vitejs/plugin-vue": "^5.2.1",
33
+ "rollup": "^4.28.1",
34
+ "rollup-plugin-gzip": "^4.0.1",
35
+ "typescript": "^5.7.2",
36
+ "vite": "^6.0.3",
37
+ "vite-plugin-dts": "^4.3.0",
38
+ "vue-tsc": "^2.1.10"
39
+ }
40
+ }
@@ -0,0 +1,70 @@
1
+ import router from "@/router/loader-router";
2
+ import { MainAppData } from "@/utils/micro-app";
3
+ import { ref, markRaw, h } from "vue";
4
+
5
+ /**
6
+ * 微模块属性配置
7
+ */
8
+ export const moduleAttrs = ref<Record<string, any>>({});
9
+ /**
10
+ * 微模块地址
11
+ */
12
+ export const moduleUrl = ref<string>("");
13
+ /**
14
+ * 微模块列表
15
+ */
16
+ export const moduleRecords = ref<Record<string, () => Promise<unknown>>>({});
17
+ /**
18
+ * 当前微模块
19
+ */
20
+ export const moduleCom = ref<any>(null);
21
+
22
+ /**
23
+ * 加载微模块
24
+ * @param module 微模块地址
25
+ */
26
+ export const loadModule = async (page: string) => {
27
+ moduleUrl.value = page;
28
+ if (page.startsWith("/")) page = page.substring(1);
29
+ const link = moduleRecords.value[
30
+ `./views/${page}.vue`
31
+ ] as () => Promise<any>;
32
+
33
+ if (link) {
34
+ const module = await link();
35
+ moduleCom.value = markRaw(module.default);
36
+ router.replace("/" + page);
37
+ } else {
38
+ console.error("加载微模块" + page + "失败");
39
+ moduleCom.value = h(
40
+ "div",
41
+ {
42
+ style: {
43
+ display: "flex",
44
+ justifyContent: "center",
45
+ alignItems: "center",
46
+ height: "100vh", // 使整个视口高度都被占满
47
+ flexDirection: "column" // 使文本垂直居中
48
+ }
49
+ },
50
+ [h("div", "404 NOT FOUND")]
51
+ );
52
+ }
53
+ };
54
+
55
+ /**
56
+ * 初始化微模块加载
57
+ * @param modules 微模块列表
58
+ */
59
+ export const initModuleLoader = (
60
+ modules: Record<string, () => Promise<unknown>>
61
+ ) => {
62
+ moduleRecords.value = modules;
63
+ if (window.microApp) {
64
+ window.microApp.addDataListener(async (data: MainAppData) => {
65
+ if (data.pageUrl === moduleUrl.value) return;
66
+ let page = data.pageUrl as string;
67
+ loadModule(page);
68
+ }, true);
69
+ }
70
+ };
@@ -0,0 +1,12 @@
1
+ <script setup lang="ts">
2
+ import { moduleCom, moduleAttrs, loadModule } from './index';
3
+ import { LoaderRouter } from '@/index';
4
+
5
+ if (!window.microApp) {
6
+ loadModule(LoaderRouter.currentRoute.value.path)
7
+ }
8
+ </script>
9
+
10
+ <template>
11
+ <component v-bind="moduleAttrs" :is="moduleCom" v-if="moduleCom != null" />
12
+ </template>