zmdms-utils 0.0.75 → 0.0.76

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.
Files changed (78) hide show
  1. package/dist/es/_virtual/_commonjsHelpers.js +3 -0
  2. package/dist/es/_virtual/_tslib.js +87 -0
  3. package/dist/es/_virtual/decimal.js +7 -0
  4. package/dist/es/_virtual/parseTimeTest.js +3 -0
  5. package/dist/es/_virtual/test.js +3 -0
  6. package/dist/es/auth.d.ts +9 -0
  7. package/dist/es/auth.js +49 -0
  8. package/dist/es/baseUrl.d.ts +23 -0
  9. package/dist/es/baseUrl.js +50 -0
  10. package/dist/es/canvas.d.ts +6 -0
  11. package/dist/es/canvas.js +14 -0
  12. package/dist/es/common.d.ts +81 -0
  13. package/dist/es/common.js +304 -0
  14. package/dist/es/constants.d.ts +20 -0
  15. package/dist/es/constants.js +33 -0
  16. package/dist/es/crypto.d.ts +51 -0
  17. package/dist/es/crypto.js +97 -0
  18. package/dist/es/file.d.ts +127 -0
  19. package/dist/es/file.js +373 -0
  20. package/dist/es/htmlToPdf.d.ts +44 -0
  21. package/dist/es/htmlToPdf.js +84 -0
  22. package/dist/es/locales/i18n.d.ts +15 -0
  23. package/dist/es/locales/t-in-non-react.d.ts +17 -0
  24. package/dist/es/locales/t-options.d.ts +7 -0
  25. package/dist/es/locales/use-translation.d.ts +42 -0
  26. package/dist/es/mainApp.d.ts +36 -0
  27. package/dist/es/mainApp.js +44 -0
  28. package/dist/es/math.d.ts +29 -0
  29. package/dist/es/math.js +147 -0
  30. package/dist/es/microAppCreator.d.ts +46 -0
  31. package/dist/es/microAppCreator.js +89 -0
  32. package/dist/es/node_modules/decimal.js/decimal.js +4896 -0
  33. package/dist/es/node_modules/decimal.js/decimal2.js +4930 -0
  34. package/dist/es/node_modules/html-parse-stringify/dist/html-parse-stringify.module.js +5 -0
  35. package/dist/es/node_modules/i18next/dist/esm/i18next.js +2242 -0
  36. package/dist/es/node_modules/js-base64/base64.js +273 -0
  37. package/dist/es/node_modules/jwt-decode/build/jwt-decode.esm.js +3 -0
  38. package/dist/es/node_modules/mitt/dist/mitt.js +3 -0
  39. package/dist/es/node_modules/pinyin-pro/dist/index.js +12627 -0
  40. package/dist/es/node_modules/react-i18next/dist/es/Trans.js +47 -0
  41. package/dist/es/node_modules/react-i18next/dist/es/TransWithoutContext.js +312 -0
  42. package/dist/es/node_modules/react-i18next/dist/es/context.js +18 -0
  43. package/dist/es/node_modules/react-i18next/dist/es/defaults.js +21 -0
  44. package/dist/es/node_modules/react-i18next/dist/es/i18nInstance.js +7 -0
  45. package/dist/es/node_modules/react-i18next/dist/es/initReactI18next.js +12 -0
  46. package/dist/es/node_modules/react-i18next/dist/es/unescape.js +27 -0
  47. package/dist/es/node_modules/react-i18next/dist/es/useTranslation.js +112 -0
  48. package/dist/es/node_modules/react-i18next/dist/es/utils.js +63 -0
  49. package/dist/es/node_modules/void-elements/index.js +23 -0
  50. package/dist/es/parseTime.d.ts +29 -0
  51. package/dist/es/parseTime.js +189 -0
  52. package/dist/es/parseTimeTest.js +2 -0
  53. package/dist/es/passwordValidate.d.ts +9 -0
  54. package/dist/es/passwordValidate.js +169 -0
  55. package/dist/es/pdf.d.ts +49 -0
  56. package/dist/es/pdf.js +176 -0
  57. package/dist/es/pinyin.js +1 -0
  58. package/dist/es/print.d.ts +23 -0
  59. package/dist/es/print.js +43 -0
  60. package/dist/es/qiankunUtils.d.ts +13 -0
  61. package/dist/es/qiankunUtils.js +32 -0
  62. package/dist/es/request.d.ts +87 -0
  63. package/dist/es/request.js +308 -0
  64. package/dist/es/src/locales/i18n.js +16 -0
  65. package/dist/es/src/locales/t-in-non-react.js +54 -0
  66. package/dist/es/src/locales/t-options.js +20 -0
  67. package/dist/es/src/locales/use-translation.js +60 -0
  68. package/dist/es/src/parseTimeTest.js +288 -0
  69. package/dist/es/src/test.js +245 -0
  70. package/dist/es/test.js +2 -0
  71. package/dist/es/validate.d.ts +26 -0
  72. package/dist/es/validate.js +47 -0
  73. package/dist/es/water.d.ts +53 -0
  74. package/dist/es/water.js +88 -0
  75. package/dist/index.d.ts +26 -0
  76. package/dist/index.js +26 -0
  77. package/package.json +1 -1
  78. package/src/math.ts +1 -1
@@ -0,0 +1,44 @@
1
+ import { IImgToPdfConfig } from './pdf.js';
2
+
3
+ interface IConfig {
4
+ /** 容器,从哪个容器里面找需要转换的元素 */
5
+ container?: HTMLElement;
6
+ /**
7
+ * 需要转换的dom 可以是一个字符串
8
+ * 如果是字符串的话 那么就是通过querySelectorAll的形式查找
9
+ * 如果是一个dom实例
10
+ * 如果是多个dom实例
11
+ **/
12
+ pageDom?: string | HTMLElement | HTMLElement[];
13
+ /**
14
+ * 是否使用canvas直接转
15
+ */
16
+ useCanvas?: boolean;
17
+ /**
18
+ * 是否生成多份PDF
19
+ */
20
+ isMultiple?: boolean;
21
+ /**
22
+ * pdf名称 默认取dom元素配置的 data-title属性
23
+ */
24
+ pdfName?: string;
25
+ /**
26
+ * pdf相关配置
27
+ */
28
+ pdfConfig?: IImgToPdfConfig["pdfConfig"];
29
+ /**
30
+ * 生成PDF的左边距
31
+ */
32
+ leftPadding?: number;
33
+ /**
34
+ * 是否下载pdf
35
+ */
36
+ isDownload?: boolean;
37
+ /**
38
+ * 水印相关
39
+ */
40
+ waterConfig?: IImgToPdfConfig["waterConfig"];
41
+ }
42
+ declare function htmlToPdf(config: IConfig): Promise<unknown>;
43
+
44
+ export { htmlToPdf };
@@ -0,0 +1,84 @@
1
+ import { __awaiter, __generator } from './_virtual/_tslib.js';
2
+ import dayjs from 'dayjs';
3
+ import { imgToPdf } from './pdf.js';
4
+ import { domToCanvas } from './canvas.js';
5
+
6
+ function htmlToPdf(config) {
7
+ var _this = this;
8
+ var container = config.container, pageDom = config.pageDom, _a = config.useCanvas, useCanvas = _a === void 0 ? true : _a, isMultiple = config.isMultiple, pdfConfig = config.pdfConfig, pdfName = config.pdfName, isDownload = config.isDownload, waterConfig = config.waterConfig, leftPadding = config.leftPadding;
9
+ // 找到需要转换的dom
10
+ var domList;
11
+ if (typeof pageDom === "string") {
12
+ domList = container
13
+ ? container.querySelectorAll(pageDom)
14
+ : document.body.querySelectorAll(pageDom);
15
+ domList = Array.from(domList);
16
+ }
17
+ else {
18
+ domList = Array.isArray(pageDom) ? pageDom : [pageDom];
19
+ }
20
+ if (domList.length === 0) {
21
+ return Promise.reject("没有可以导出的元素!");
22
+ }
23
+ if (!useCanvas) {
24
+ // 直接导出html 待实现
25
+ return Promise.resolve();
26
+ }
27
+ // 通过html => canvas => pdf 的形式导出
28
+ // 多份导出
29
+ if (isMultiple) {
30
+ var promiseArr_1 = [];
31
+ domList.forEach(function (domItem, index) {
32
+ var dataTitle = domItem.dataset.title || "".concat(dayjs().format("YYYY-MM-DD"), "-").concat(index + 1);
33
+ var item = domToCanvas(domItem).then(function (canvas) { return __awaiter(_this, void 0, void 0, function () {
34
+ var canvasWidth, canvasHeight, pdf;
35
+ return __generator(this, function (_a) {
36
+ switch (_a.label) {
37
+ case 0:
38
+ canvasWidth = canvas.width;
39
+ canvasHeight = canvas.height;
40
+ return [4 /*yield*/, imgToPdf({
41
+ images: {
42
+ image: canvas,
43
+ width: canvasWidth,
44
+ height: canvasHeight,
45
+ },
46
+ pdfConfig: pdfConfig,
47
+ leftPadding: leftPadding,
48
+ pdfDownloadConfig: {
49
+ isDownload: isDownload,
50
+ pdfName: pdfName ? pdfName : dataTitle,
51
+ },
52
+ waterConfig: waterConfig,
53
+ })];
54
+ case 1:
55
+ pdf = _a.sent();
56
+ return [2 /*return*/, pdf];
57
+ }
58
+ });
59
+ }); });
60
+ promiseArr_1.push(item);
61
+ });
62
+ return Promise.all(promiseArr_1);
63
+ }
64
+ else {
65
+ // 创建canvas组
66
+ var promiseArr = domList.map(function (domItem, index) {
67
+ return domToCanvas(domItem);
68
+ });
69
+ var dataTitle = domList[0].dataset.title || "".concat(dayjs().format("YYYY-MM-DD"));
70
+ // 合并成一个pdf导出
71
+ return imgToPdf({
72
+ images: promiseArr,
73
+ pdfConfig: pdfConfig,
74
+ pdfDownloadConfig: {
75
+ isDownload: isDownload,
76
+ pdfName: pdfName ? pdfName : dataTitle,
77
+ },
78
+ waterConfig: waterConfig,
79
+ leftPadding: leftPadding,
80
+ });
81
+ }
82
+ }
83
+
84
+ export { htmlToPdf };
@@ -0,0 +1,15 @@
1
+ import i18next__default from 'i18next';
2
+ export { default as i18n } from 'i18next';
3
+
4
+ type InitOptions = Parameters<typeof i18next__default.init>;
5
+ /**
6
+ * 初始化逻辑
7
+ * - 本函数主要用于初始化 i18next 实例,同时使用 react-i18next 插件进行 react 组件的支持
8
+ * - 本函数的调用时机,一般是在项目的入口文件中进行调用,如 src/main.tsx 中
9
+ * @param options 参数 同i18next.init 第一个参数
10
+ * @param callback 参数 同i18next.init 第二个参数
11
+ * @returns
12
+ */
13
+ declare function initLocale(options: InitOptions[0], callback?: InitOptions[1]): Promise<i18next__default.TFunction<"translation", undefined>>;
14
+
15
+ export { initLocale };
@@ -0,0 +1,17 @@
1
+ import { TOpionsEx } from './t-options.js';
2
+
3
+ /**
4
+ * 同步版本的 i18n.t 函数(应对在 react 组件外使用的翻译函数)
5
+ * - 如果 i18n 未初始化,则返回默认值或键名
6
+ * - 如果 i18n 初始化后,键名不存在,则返回默认值或键名
7
+ * - 其他正常情况(已经初始化+键名存在),则返回翻译值
8
+ * @description 本函数为在非 react 组件中使用的翻译函数;(在react中请求使用 useTranslate() 返回的 t 函数)
9
+ * @param {string} key
10
+ * @param {TOpionsEx|string} defaultValue 必填值
11
+ * @returns {string}
12
+ * @example
13
+ * const txt = t('someLocaleKey', '兜底默认值');
14
+ */
15
+ declare function safeT(key: string, defaultValueOrOptions: string | TOpionsEx): string;
16
+
17
+ export { safeT };
@@ -0,0 +1,7 @@
1
+ import { TOptions } from 'i18next';
2
+
3
+ interface TOpionsEx extends TOptions {
4
+ defaultValue: string;
5
+ }
6
+
7
+ export { TOpionsEx };
@@ -0,0 +1,42 @@
1
+ import * as i18next from 'i18next';
2
+ import { useTranslation } from 'react-i18next';
3
+ export { Trans } from 'react-i18next';
4
+ import { TOpionsEx } from './t-options.js';
5
+
6
+ type Prams = Parameters<typeof useTranslation>;
7
+ type NS = Prams[0];
8
+ type Options = Prams[1];
9
+ type EnhanceTFunc = (key: string, defaultValueOrOptions: string | TOpionsEx) => string;
10
+ /**
11
+ * 这里只是简单代理一下useTranslation,方便后续扩展或添加其他逻辑
12
+ * @param ns 命名空间 大多数情况下都不需要传入这个参数,除非你用到了命名空间。
13
+ * @param options 其他参数 大多数情况下,都不需要关注这个参数。
14
+ * options.keyPrefix 为所有翻译键添加前缀
15
+ * // JSON 文件:{ "greeting": { "welcome": "Welcome" } }
16
+ * const { t } = useTranslation('common', { keyPrefix: 'greeting' });
17
+ * // 使用时省略前缀
18
+ * t('welcome'); // 等价于 t('greeting:welcome')
19
+ * @returns { t, i18n, ready }
20
+ * t: 翻译方法
21
+ * i18n: i18next实例 访问 i18next 的完整 API(如切换语言、加载命名空间)
22
+ * i18n.changeLanguage('zh-CN'); 使用它切换语言,可以触发组件渲染。但是当前项目中是使用全局刷新的模式,来更新语言的。
23
+ * ready: 是否加载完成
24
+ */
25
+ declare function useZtTranslation(ns?: NS, options?: Options): {
26
+ /**
27
+ * t函数的使用方式:基本上使用1、2两种方式就可以了。
28
+ * 1、t('key') // 基础用法
29
+ * 2、t('greeting', { name: 'John' }); // 对应 JSON: "greeting": "Hello {{name}}"
30
+ * 3、t('auth:login'); // 显式指定命名空间
31
+ *
32
+ * 关于t函数的第二个参数的说明。
33
+ * 为了防止一些异常情况,翻译失败。可以传入一个默认值。这个默认值就是原本的中文就行。
34
+ * 1、t('key', '默认值');
35
+ * 2、t('key', { defaultValue: '默认值', ...otherOptions });
36
+ */
37
+ t: EnhanceTFunc;
38
+ i18n: i18next.i18n;
39
+ ready: boolean;
40
+ };
41
+
42
+ export { useZtTranslation as useTranslation };
@@ -0,0 +1,36 @@
1
+ interface IEntry {
2
+ scripts?: string[];
3
+ styles?: string[];
4
+ html?: string;
5
+ }
6
+ type IActiveRule = (location: Location) => boolean;
7
+ interface IMicroApp {
8
+ name: string;
9
+ entry: string | IEntry;
10
+ container: string | HTMLElement;
11
+ activeRule: string | string[] | IActiveRule | IActiveRule[];
12
+ loader?: (loading: boolean) => void;
13
+ props?: object;
14
+ }
15
+ interface IOtherOptions {
16
+ /** 过滤掉的一些资源的关键词,必须保证不过滤掉一些不该过滤的东西 */
17
+ whiteWords?: string[];
18
+ /** loading 发生变化触发事件 */
19
+ loader?: (loading: boolean) => void;
20
+ startOptions?: any;
21
+ }
22
+ /**
23
+ * 主应用初始化逻辑
24
+ * @param microApps 子应用列表
25
+ * @param defaultAppLink 设置主应用启动后默认进入的微应用
26
+ * @param otherOptions
27
+ */
28
+ declare function initMainApp(microApps: IMicroApp[], defaultAppLink: string, otherOptions?: IOtherOptions): void;
29
+ /**
30
+ * 全局错误处理
31
+ * @param handle 错误函数
32
+ * @returns 清空监听
33
+ */
34
+ declare function initGlobalError(handle: (event: any) => void): () => void;
35
+
36
+ export { IMicroApp, initGlobalError, initMainApp };
@@ -0,0 +1,44 @@
1
+ import { __assign } from './_virtual/_tslib.js';
2
+ import { registerMicroApps, setDefaultMountApp, start, runAfterFirstMounted, addGlobalUncaughtErrorHandler, removeGlobalUncaughtErrorHandler } from 'qiankun';
3
+
4
+ /**
5
+ * 主应用初始化逻辑
6
+ * @param microApps 子应用列表
7
+ * @param defaultAppLink 设置主应用启动后默认进入的微应用
8
+ * @param otherOptions
9
+ */
10
+ function initMainApp(microApps, defaultAppLink, otherOptions) {
11
+ if (otherOptions === void 0) { otherOptions = {}; }
12
+ var _a = otherOptions.whiteWords, whiteWords = _a === void 0 ? [] : _a, loader = otherOptions.loader, _b = otherOptions.startOptions, startOptions = _b === void 0 ? {} : _b;
13
+ /**
14
+ * Step2 注册子应用
15
+ */
16
+ registerMicroApps(microApps.map(function (item) { return (__assign(__assign({}, item), { loader: loader })); }));
17
+ /**
18
+ * Setp3 设置默认进入的子应用
19
+ */
20
+ setDefaultMountApp(defaultAppLink);
21
+ /**
22
+ * Setp4 启动应用
23
+ */
24
+ start(__assign({ excludeAssetFilter: function (urls) {
25
+ // 指定部分特殊的动态加载的微应用资源(css/js) 不被 qiankun 劫持处理
26
+ return whiteWords.some(function (w) { return urls.includes(w); });
27
+ } }, startOptions));
28
+ runAfterFirstMounted(function () {
29
+ console.log("第一个微应用加载成功!");
30
+ });
31
+ }
32
+ /**
33
+ * 全局错误处理
34
+ * @param handle 错误函数
35
+ * @returns 清空监听
36
+ */
37
+ function initGlobalError(handle) {
38
+ addGlobalUncaughtErrorHandler(handle);
39
+ return function () {
40
+ removeGlobalUncaughtErrorHandler(handle);
41
+ };
42
+ }
43
+
44
+ export { initGlobalError, initMainApp };
@@ -0,0 +1,29 @@
1
+ type numType = number | string;
2
+ /**
3
+ * 加法
4
+ */
5
+ declare function plus(num1: numType, num2: numType): number;
6
+ /**
7
+ * 减法
8
+ */
9
+ declare function minus(num1: numType, num2: numType): number;
10
+ /**
11
+ * 乘法
12
+ */
13
+ declare function times(num1: numType, num2: numType): number;
14
+ /**
15
+ * 除法
16
+ */
17
+ declare function divide(num1: numType, num2: numType, precision?: number): number;
18
+ /**
19
+ * 四舍五入保留小数
20
+ */
21
+ declare function exactRound(num: numType, ratio: number): numType;
22
+ /**
23
+ * 将字节数加上合适的单位
24
+ * @param numBytes 字节数
25
+ * @returns
26
+ */
27
+ declare function formatUnit(numBytes: number): string | number;
28
+
29
+ export { divide, exactRound, formatUnit, minus, plus, times };
@@ -0,0 +1,147 @@
1
+ import { Decimal } from './node_modules/decimal.js/decimal.js';
2
+
3
+ /**
4
+ * 如果传入的数,有非数字的情况 那么忽略这个数
5
+ * 非数字的情况包括 null undefined
6
+ * 因为null转数字的结果是 0 可能会影响计算结果。
7
+ * 而这个可能不符合预期
8
+ */
9
+ function initNum(num1, num2) {
10
+ // 如果两个数都是非数字 那么直接返回0
11
+ if (isNaN(num1) && isNaN(num2)) {
12
+ return 0;
13
+ }
14
+ if (isNaN(num1)) {
15
+ return num2;
16
+ }
17
+ if (isNaN(num2)) {
18
+ return num1;
19
+ }
20
+ }
21
+ /**
22
+ * 加法
23
+ */
24
+ function plus(num1, num2) {
25
+ try {
26
+ var _num1 = num1 == null ? NaN : Number(num1);
27
+ var _num2 = num2 == null ? NaN : Number(num2);
28
+ // 如果两个数都是非数字 那么直接返回0
29
+ var result = initNum(_num1, _num2);
30
+ if (typeof result === "number") {
31
+ return result;
32
+ }
33
+ return new Decimal(_num1).add(_num2).toNumber();
34
+ // return (isNaN(_num1) ? 0 : _num1) + (isNaN(_num2) ? 0 : _num2);
35
+ }
36
+ catch (err) {
37
+ console.error("计算加法出错", err);
38
+ return 0;
39
+ }
40
+ }
41
+ /**
42
+ * 减法
43
+ */
44
+ function minus(num1, num2) {
45
+ try {
46
+ var _num1 = num1 == null ? NaN : Number(num1);
47
+ var _num2 = num2 == null ? NaN : Number(num2);
48
+ // 如果两个数都是非数字 那么直接返回0
49
+ var result = initNum(_num1, _num2);
50
+ if (typeof result === "number") {
51
+ return result;
52
+ }
53
+ return new Decimal(_num1).sub(_num2).toNumber();
54
+ // return (isNaN(_num1) ? 0 : _num1) - (isNaN(_num2) ? 0 : _num2);
55
+ }
56
+ catch (err) {
57
+ console.error("计算减法出错", err);
58
+ return 0;
59
+ }
60
+ }
61
+ /**
62
+ * 乘法
63
+ */
64
+ function times(num1, num2) {
65
+ try {
66
+ var _num1 = num1 == null ? NaN : Number(num1);
67
+ var _num2 = num2 == null ? NaN : Number(num2);
68
+ // 如果两个数都是非数字 那么直接返回0
69
+ var result = initNum(_num1, _num2);
70
+ if (typeof result === "number") {
71
+ return result;
72
+ }
73
+ return new Decimal(_num1).mul(_num2).toNumber();
74
+ // return (isNaN(_num1) ? 0 : _num1) * (isNaN(_num2) ? 0 : _num2);
75
+ }
76
+ catch (err) {
77
+ console.error("计算乘法出错", err);
78
+ return 0;
79
+ }
80
+ }
81
+ /**
82
+ * 除法
83
+ */
84
+ function divide(num1, num2, precision) {
85
+ if (precision === void 0) { precision = 5; }
86
+ try {
87
+ var _num1 = num1 == null ? NaN : Number(num1);
88
+ var _num2 = num2 == null ? NaN : Number(num2);
89
+ // 如果两个数都是非数字 那么直接返回0
90
+ var result = initNum(_num1, _num2);
91
+ if (typeof result === "number") {
92
+ return result;
93
+ }
94
+ // FIXME: 不记得这里为什么要先设置下小数位了。
95
+ // 会影响其他值的计算.
96
+ // Decimal.set({ precision });
97
+ // return new Decimal(_num1).div(_num2).toNumber();
98
+ // 这里改成这种模式。行为基本与之前是一致的
99
+ return Number(new Decimal(_num1).div(_num2).toFixed(precision));
100
+ }
101
+ catch (err) {
102
+ console.error("计算除法出错", err);
103
+ return 0;
104
+ }
105
+ }
106
+ /**
107
+ * 四舍五入保留小数
108
+ */
109
+ function exactRound(num, ratio) {
110
+ try {
111
+ var _num1 = num == null ? NaN : Number(num);
112
+ if (isNaN(_num1)) {
113
+ return 0;
114
+ // return (0).toFixed(ratio);
115
+ }
116
+ var value = new Decimal(num).toFixed(ratio);
117
+ // 设置exactRound去掉小数位后面的0
118
+ if (window.__EXACT_ROUND_TYPE__ === "TRIM_ZEROS") {
119
+ value = Number(value);
120
+ }
121
+ return value;
122
+ // return Number(num).toFixed(ratio);
123
+ }
124
+ catch (err) {
125
+ return num;
126
+ }
127
+ }
128
+ /**
129
+ * 将字节数加上合适的单位
130
+ * @param numBytes 字节数
131
+ * @returns
132
+ */
133
+ function formatUnit(numBytes) {
134
+ var _numBytes = Number(numBytes);
135
+ if (isNaN(_numBytes)) {
136
+ return numBytes;
137
+ }
138
+ var units = ["B", "KB", "MB", "GB", "TB"];
139
+ var unitIndex = 0;
140
+ while (_numBytes >= 1024 && unitIndex < units.length - 1) {
141
+ _numBytes /= 1024;
142
+ unitIndex++;
143
+ }
144
+ return _numBytes.toFixed(2) + units[unitIndex];
145
+ }
146
+
147
+ export { divide, exactRound, formatUnit, minus, plus, times };
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @description 微应用初始化
3
+ * @param render 加载应用方法
4
+ * @param microAppOptions 微应用的一些配置
5
+ */
6
+ interface IMicroAppOptions {
7
+ /**
8
+ * @deprecated 该属性已废弃,无意义
9
+ */
10
+ microAppContainerId: string;
11
+ microAppKey: string;
12
+ /**
13
+ * @deprecated 该属性已废弃,无意义
14
+ */
15
+ microAppRoot: any;
16
+ /**
17
+ * 只会在微应用初始化的时候调用一次,下次微应用重新进入时会直接调用 mount 钩子,不会再重复触发 bootstrap
18
+ * 通常我们可以在这里做一些全局变量的初始化,比如不会在 unmount 阶段被销毁的应用级别的缓存等。
19
+ **/
20
+ microAppBootstrapHandle?: () => void;
21
+ /**
22
+ * 应用每次进入都会调用 mount 方法,通常我们在这里触发应用的渲染方法
23
+ */
24
+ microAppMountHandle: (props: any) => void;
25
+ /**
26
+ * 应用每次 切出/卸载 会调用的方法,通常在这里我们会卸载微应用的应用实例
27
+ */
28
+ microAppUnMountHandle: (props: any) => void;
29
+ /**
30
+ * 可选生命周期钩子,仅使用 loadMicroApp 方式加载微应用时生效
31
+ */
32
+ microAppUpdateHandle?: (props: any) => void;
33
+ }
34
+ declare function initMicroApp(render: any, microAppOptions: IMicroAppOptions): {
35
+ bootstrap?: undefined;
36
+ mount?: undefined;
37
+ unmount?: undefined;
38
+ update?: undefined;
39
+ } | {
40
+ bootstrap: () => Promise<void>;
41
+ mount: (props: any) => Promise<void>;
42
+ unmount: (props: any) => Promise<void>;
43
+ update: (props: any) => Promise<void>;
44
+ };
45
+
46
+ export { IMicroAppOptions, initMicroApp };
@@ -0,0 +1,89 @@
1
+ import { __awaiter, __generator } from './_virtual/_tslib.js';
2
+ import { isQiankun } from './qiankunUtils.js';
3
+
4
+ /**
5
+ * 可选生命周期钩子,仅使用 loadMicroApp 方式加载微应用时生效
6
+ */
7
+ function update(props) {
8
+ console.log("可以在update声明周期中做的一些公共处理的事!", props);
9
+ }
10
+ function initMicroApp(render, microAppOptions) {
11
+ // 初始加载应用
12
+ // 1. 如果不是微前端环境,那么应用直接运行
13
+ if (!isQiankun()) {
14
+ render({});
15
+ return {};
16
+ }
17
+ // 2. 进入微前端环境的运行逻辑
18
+ var microAppKey = microAppOptions.microAppKey, microAppBootstrapHandle = microAppOptions.microAppBootstrapHandle, microAppMountHandle = microAppOptions.microAppMountHandle, microAppUnMountHandle = microAppOptions.microAppUnMountHandle, microAppUpdateHandle = microAppOptions.microAppUpdateHandle;
19
+ // 唯一key没传 给出开发提示
20
+ if (!microAppKey) {
21
+ throw Error("\u6CA1\u6709\u914D\u7F6E\u5FAE\u5E94\u7528\u7684\u552F\u4E00key\u503C\uFF0C\u8FD9\u4F1A\u5BFC\u81F4\u5FAE\u524D\u7AEF\u8FD0\u884C\u51FA\u9519\uFF01");
22
+ }
23
+ /**
24
+ * bootstrap 只会在微应用初始化的时候调用一次,下次微应用重新进入时会直接调用 mount 钩子,不会再重复触发 bootstrap。
25
+ * 通常我们可以在这里做一些全局变量的初始化,比如不会在 unmount 阶段被销毁的应用级别的缓存等。
26
+ */
27
+ function bootstrap() {
28
+ return __awaiter(this, void 0, void 0, function () {
29
+ return __generator(this, function (_a) {
30
+ console.log("\u5FAE\u5E94\u7528==".concat(microAppKey, "==bootstraped"));
31
+ if (microAppBootstrapHandle) {
32
+ microAppBootstrapHandle();
33
+ }
34
+ return [2 /*return*/];
35
+ });
36
+ });
37
+ }
38
+ /**
39
+ * 应用每次进入都会调用 mount 方法,通常我们在这里触发应用的渲染方法
40
+ */
41
+ function mount(props) {
42
+ return __awaiter(this, void 0, void 0, function () {
43
+ return __generator(this, function (_a) {
44
+ console.log("\u5FAE\u5E94\u7528==".concat(microAppKey, "==mount"));
45
+ if (microAppMountHandle) {
46
+ microAppMountHandle(props);
47
+ }
48
+ render(props);
49
+ return [2 /*return*/];
50
+ });
51
+ });
52
+ }
53
+ /**
54
+ * 应用每次 切出/卸载 会调用的方法,通常在这里我们会卸载微应用的应用实例
55
+ */
56
+ function unmount(props) {
57
+ return __awaiter(this, void 0, void 0, function () {
58
+ return __generator(this, function (_a) {
59
+ console.log("\u5FAE\u5E94\u7528==".concat(microAppKey, "==unmount"));
60
+ if (microAppUnMountHandle) {
61
+ microAppUnMountHandle(props);
62
+ }
63
+ return [2 /*return*/];
64
+ });
65
+ });
66
+ }
67
+ /**
68
+ * 应用每次 切出/卸载 会调用的方法,通常在这里我们会卸载微应用的应用实例
69
+ */
70
+ function update(props) {
71
+ return __awaiter(this, void 0, void 0, function () {
72
+ return __generator(this, function (_a) {
73
+ console.log("\u5FAE\u5E94\u7528==".concat(microAppKey, "==update"));
74
+ if (microAppUpdateHandle) {
75
+ microAppUpdateHandle(props);
76
+ }
77
+ return [2 /*return*/];
78
+ });
79
+ });
80
+ }
81
+ return {
82
+ bootstrap: bootstrap,
83
+ mount: mount,
84
+ unmount: unmount,
85
+ update: update,
86
+ };
87
+ }
88
+
89
+ export { initMicroApp, update };