zmdms-utils 0.0.5 → 0.0.7

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 +1,11 @@
1
1
  ## 公用方法,用于存放一些与框架、平台无关的方法
2
+
3
+ ```
4
+ /**
5
+ * 这种注释不会被删除
6
+ */
7
+
8
+ // 这种注释会被删除
9
+
10
+ /* 这种也会被删除 */
11
+ ```
package/dist/es/auth.d.ts CHANGED
@@ -3,5 +3,6 @@
3
3
  */
4
4
  declare function getToken(): string | null;
5
5
  declare function setToken(token: string): void;
6
+ declare function removeToken(): void;
6
7
 
7
- export { getToken, setToken };
8
+ export { getToken, removeToken, setToken };
package/dist/es/auth.js CHANGED
@@ -18,5 +18,13 @@ function setToken(token) {
18
18
  console.error("设置token失败", err);
19
19
  }
20
20
  }
21
+ function removeToken() {
22
+ try {
23
+ window.localStorage.removeItem("system-token");
24
+ }
25
+ catch (err) {
26
+ console.error("设置token失败", err);
27
+ }
28
+ }
21
29
 
22
- export { getToken, setToken };
30
+ export { getToken, removeToken, setToken };
@@ -0,0 +1,6 @@
1
+ declare function getBaseUrl(processObj: any): {
2
+ api: any;
3
+ file: any;
4
+ };
5
+
6
+ export { getBaseUrl };
@@ -1,3 +1,25 @@
1
- function getBaseUrl() { }
1
+ // 根据当前环境变量获取基础的URL
2
+ function getBaseUrl(processObj) {
3
+ var ENV = processObj.REACT_APP_ENV; // 获取当前环境变量
4
+ // api各个环境地址
5
+ var apiBaseUrlObj = {
6
+ dev: processObj.REACT_APP_API_DEV || "http://192.168.0.83:8000",
7
+ test: processObj.REACT_APP_API_TEST || window.location.origin,
8
+ stage: processObj.REACT_APP_API_STAGE || window.location.origin,
9
+ product: processObj.REACT_APP_API_PRODUCT || window.location.origin,
10
+ };
11
+ // file 服务器
12
+ var fileBaseUrlObj = {
13
+ dev: processObj.REACT_APP_FILE_DEV || "http://192.168.0.83:88",
14
+ test: processObj.REACT_APP_FILE_TEST || "http://172.55.5.101:33013",
15
+ stage: processObj.REACT_APP_FILE_STAGE || "https://dzfile-prod.zmd.com.cn",
16
+ product: processObj.REACT_APP_FILE_PRODUCT || "https://dzfile.zmd.com.cn:8012",
17
+ };
18
+ var currentKey = ENV.toLowerCase() || "dev";
19
+ return {
20
+ api: apiBaseUrlObj[currentKey],
21
+ file: fileBaseUrlObj[currentKey],
22
+ };
23
+ }
2
24
 
3
25
  export { getBaseUrl };
@@ -0,0 +1,39 @@
1
+ import * as mitt from 'mitt';
2
+
3
+ /**
4
+ * 同步阻断
5
+ * @param time 秒
6
+ */
7
+ declare function delay(time: number): void;
8
+ /**
9
+ * 发布订阅实例
10
+ */
11
+ declare const emitter: mitt.Emitter<Record<mitt.EventType, unknown>>;
12
+ /**
13
+ * 添加位数分割符
14
+ * @param n 需要分割的字符
15
+ * @param digit 多少位分割
16
+ * @param symbol 添加的符号
17
+ * @returns
18
+ */
19
+ declare function addThousedSeparator(n: any, digit?: number, symbol?: string): any;
20
+ /**
21
+ * 获取地址栏参数
22
+ * @returns 地址栏参数对象
23
+ */
24
+ declare function parseQueryParams(url: string): {
25
+ [key: string]: string;
26
+ };
27
+ /**
28
+ * 将一些转义字符转换成原先的字符
29
+ * @param input 需要转换的内容
30
+ * @returns 转换过后的结果
31
+ */
32
+ declare function unescapeString(input: string): string;
33
+ /**
34
+ * 将内容复制到粘贴板中
35
+ * @param text 需要复制的内容
36
+ */
37
+ declare function copyToClipboard(text: string, callback?: any): void;
38
+
39
+ export { addThousedSeparator, copyToClipboard, delay, emitter, parseQueryParams, unescapeString };
@@ -0,0 +1,143 @@
1
+ import mitt from './node_modules/mitt/dist/mitt.js';
2
+
3
+ // 基础函数
4
+ /**
5
+ * 同步阻断
6
+ * @param time 秒
7
+ */
8
+ function delay(time) {
9
+ }
10
+ /**
11
+ * 发布订阅实例
12
+ */
13
+ var emitter = mitt();
14
+ /**
15
+ * 添加位数分割符
16
+ * @param n 需要分割的字符
17
+ * @param digit 多少位分割
18
+ * @param symbol 添加的符号
19
+ * @returns
20
+ */
21
+ function addThousedSeparator(n, digit, symbol) {
22
+ if (digit === void 0) { digit = 3; }
23
+ if (symbol === void 0) { symbol = ","; }
24
+ if (n != null) {
25
+ var _n = n.toString();
26
+ var pointBeforeNum = "";
27
+ var pointAfterNum = "";
28
+ if (_n.startsWith("-")) {
29
+ pointBeforeNum = "-";
30
+ _n = _n.slice(1);
31
+ }
32
+ var pointIndex = _n.indexOf(".");
33
+ if (pointIndex !== -1) {
34
+ n = _n.slice(0, pointIndex);
35
+ pointAfterNum = _n.slice(pointIndex);
36
+ }
37
+ else {
38
+ n = _n;
39
+ }
40
+ var res = "";
41
+ var s = n.toString();
42
+ var length_1 = s.length;
43
+ for (var i = length_1 - 1; i >= 0; i--) {
44
+ var j = length_1 - i;
45
+ if (j % digit === 0) {
46
+ if (i === 0) {
47
+ res = s[i] + res;
48
+ }
49
+ else {
50
+ res = symbol + s[i] + res;
51
+ }
52
+ }
53
+ else {
54
+ res = s[i] + res;
55
+ }
56
+ }
57
+ return pointBeforeNum + res + pointAfterNum;
58
+ }
59
+ else {
60
+ return n;
61
+ }
62
+ }
63
+ /**
64
+ * 获取地址栏参数
65
+ * @returns 地址栏参数对象
66
+ */
67
+ function parseQueryParams(url) {
68
+ if (!url) {
69
+ return {};
70
+ }
71
+ var queryString = url.split("?")[1];
72
+ var params = new URLSearchParams(queryString);
73
+ var result = {};
74
+ params.forEach(function (value, key) {
75
+ var val = decodeURIComponent(value);
76
+ if (val.startsWith("{")) {
77
+ try {
78
+ val = JSON.parse(val);
79
+ }
80
+ catch (err) {
81
+ console.log("解析失败", err);
82
+ }
83
+ }
84
+ else if (val === "true" || val === "false") {
85
+ val = val === "true";
86
+ }
87
+ result[key] = val;
88
+ });
89
+ return result;
90
+ }
91
+ /**
92
+ * 将一些转义字符转换成原先的字符
93
+ * @param input 需要转换的内容
94
+ * @returns 转换过后的结果
95
+ */
96
+ function unescapeString(input) {
97
+ if (!input) {
98
+ return "";
99
+ }
100
+ var escapedChars = {
101
+ "&amp;": "&",
102
+ "&lt;": "<",
103
+ "&gt;": ">",
104
+ "&quot;": '"',
105
+ "&#039;": "'",
106
+ };
107
+ return input.replace(/&(amp|lt|gt|quot|#039);/g, function (match) {
108
+ return escapedChars[match] || match;
109
+ });
110
+ }
111
+ /**
112
+ * 将内容复制到粘贴板中
113
+ * @param text 需要复制的内容
114
+ */
115
+ function copyToClipboard(text, callback) {
116
+ var _a, _b;
117
+ try {
118
+ if ((navigator === null || navigator === void 0 ? void 0 : navigator.clipboard) && window.isSecureContext) {
119
+ (_b = (_a = navigator.clipboard) === null || _a === void 0 ? void 0 : _a.writeText(text)) === null || _b === void 0 ? void 0 : _b.then(function () {
120
+ callback && callback(1);
121
+ });
122
+ }
123
+ else {
124
+ var textarea = document.createElement("textarea");
125
+ textarea.value = text;
126
+ document.body.appendChild(textarea);
127
+ textarea.select();
128
+ if (document.execCommand) {
129
+ callback && callback(1);
130
+ document.execCommand("copy");
131
+ }
132
+ else {
133
+ callback && callback(0);
134
+ }
135
+ document.body.removeChild(textarea);
136
+ }
137
+ }
138
+ catch (err) {
139
+ callback && callback(0);
140
+ }
141
+ }
142
+
143
+ export { addThousedSeparator, copyToClipboard, delay, emitter, parseQueryParams, unescapeString };
@@ -0,0 +1,48 @@
1
+ declare class Crypto {
2
+ private aesKey;
3
+ private desKey;
4
+ constructor(aesKey: string, desKey: string);
5
+ /**
6
+ * aes 加密方法
7
+ * @param data
8
+ * @returns {*}
9
+ */
10
+ encrypt(data: string): string;
11
+ /**
12
+ * aes 解密方法
13
+ * @param data
14
+ * @returns {*}
15
+ */
16
+ decrypt(data: string): string;
17
+ /**
18
+ * des 加密方法
19
+ * @param data
20
+ * @returns {*}
21
+ */
22
+ encrypt_des(data: string): string;
23
+ /**
24
+ * des 解密方法
25
+ * @param data
26
+ * @returns {*}
27
+ */
28
+ decrypt_des(data: string): string;
29
+ /**
30
+ * aes 加密方法,同java:AesUtil.encryptToBase64(text, aesKey);
31
+ */
32
+ private encryptAES;
33
+ /**
34
+ * aes 解密方法,同java:AesUtil.decryptFormBase64ToString(encrypt, aesKey);
35
+ */
36
+ private decryptAES;
37
+ /**
38
+ * des 加密方法,同java:DesUtil.encryptToBase64(text, desKey)
39
+ */
40
+ private encryptDES;
41
+ /**
42
+ * des 解密方法,同java:DesUtil.decryptFormBase64(encryptBase64, desKey);
43
+ */
44
+ private decryptDES;
45
+ }
46
+ declare const md5: (str: string) => string;
47
+
48
+ export { Crypto, md5 };
@@ -0,0 +1,93 @@
1
+ import CryptoJS from 'crypto-js';
2
+
3
+ var Crypto = /** @class */ (function () {
4
+ function Crypto(aesKey, desKey) {
5
+ this.aesKey = aesKey;
6
+ this.desKey = desKey;
7
+ }
8
+ /**
9
+ * aes 加密方法
10
+ * @param data
11
+ * @returns {*}
12
+ */
13
+ Crypto.prototype.encrypt = function (data) {
14
+ return this.encryptAES(data, this.aesKey);
15
+ };
16
+ /**
17
+ * aes 解密方法
18
+ * @param data
19
+ * @returns {*}
20
+ */
21
+ Crypto.prototype.decrypt = function (data) {
22
+ return this.decryptAES(data, this.aesKey);
23
+ };
24
+ /**
25
+ * des 加密方法
26
+ * @param data
27
+ * @returns {*}
28
+ */
29
+ Crypto.prototype.encrypt_des = function (data) {
30
+ return this.encryptDES(data, this.desKey);
31
+ };
32
+ /**
33
+ * des 解密方法
34
+ * @param data
35
+ * @returns {*}
36
+ */
37
+ Crypto.prototype.decrypt_des = function (data) {
38
+ return this.decryptDES(data, this.desKey);
39
+ };
40
+ /**
41
+ * aes 加密方法,同java:AesUtil.encryptToBase64(text, aesKey);
42
+ */
43
+ Crypto.prototype.encryptAES = function (data, key) {
44
+ var dataBytes = CryptoJS.enc.Utf8.parse(data);
45
+ var keyBytes = CryptoJS.enc.Utf8.parse(key);
46
+ var encrypted = CryptoJS.AES.encrypt(dataBytes, keyBytes, {
47
+ iv: keyBytes,
48
+ mode: CryptoJS.mode.CBC,
49
+ padding: CryptoJS.pad.Pkcs7,
50
+ });
51
+ return CryptoJS.enc.Base64.stringify(encrypted.ciphertext);
52
+ };
53
+ /**
54
+ * aes 解密方法,同java:AesUtil.decryptFormBase64ToString(encrypt, aesKey);
55
+ */
56
+ Crypto.prototype.decryptAES = function (data, key) {
57
+ var keyBytes = CryptoJS.enc.Utf8.parse(key);
58
+ var decrypted = CryptoJS.AES.decrypt(data, keyBytes, {
59
+ iv: keyBytes,
60
+ mode: CryptoJS.mode.CBC,
61
+ padding: CryptoJS.pad.Pkcs7,
62
+ });
63
+ return CryptoJS.enc.Utf8.stringify(decrypted);
64
+ };
65
+ /**
66
+ * des 加密方法,同java:DesUtil.encryptToBase64(text, desKey)
67
+ */
68
+ Crypto.prototype.encryptDES = function (data, key) {
69
+ var keyHex = CryptoJS.enc.Utf8.parse(key);
70
+ var encrypted = CryptoJS.DES.encrypt(data, keyHex, {
71
+ mode: CryptoJS.mode.ECB,
72
+ padding: CryptoJS.pad.Pkcs7,
73
+ });
74
+ return encrypted.toString();
75
+ };
76
+ /**
77
+ * des 解密方法,同java:DesUtil.decryptFormBase64(encryptBase64, desKey);
78
+ */
79
+ Crypto.prototype.decryptDES = function (data, key) {
80
+ var keyHex = CryptoJS.enc.Utf8.parse(key);
81
+ var decrypted = CryptoJS.DES.decrypt({
82
+ ciphertext: CryptoJS.enc.Base64.parse(data),
83
+ }, keyHex, {
84
+ mode: CryptoJS.mode.ECB,
85
+ padding: CryptoJS.pad.Pkcs7,
86
+ });
87
+ return decrypted.toString(CryptoJS.enc.Utf8);
88
+ };
89
+ return Crypto;
90
+ }());
91
+ var md5 = function (str) { return CryptoJS.MD5(str).toString().toLowerCase(); };
92
+
93
+ export { Crypto, md5 };
@@ -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): number;
18
+ /**
19
+ * 四舍五入保留小数
20
+ */
21
+ declare function exactRound(num: numType, ratio: number): string;
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,87 @@
1
+ /**
2
+ * 加法
3
+ */
4
+ function plus(num1, num2) {
5
+ try {
6
+ var _num1 = Number(num1);
7
+ var _num2 = Number(num2);
8
+ return (isNaN(_num1) ? 0 : _num1) + (isNaN(_num2) ? 0 : _num2);
9
+ }
10
+ catch (err) {
11
+ console.error("计算加法出错", err);
12
+ return 0;
13
+ }
14
+ }
15
+ /**
16
+ * 减法
17
+ */
18
+ function minus(num1, num2) {
19
+ try {
20
+ var _num1 = Number(num1);
21
+ var _num2 = Number(num2);
22
+ return (isNaN(_num1) ? 0 : _num1) - (isNaN(_num2) ? 0 : _num2);
23
+ }
24
+ catch (err) {
25
+ console.error("计算减法出错", err);
26
+ return 0;
27
+ }
28
+ }
29
+ /**
30
+ * 乘法
31
+ */
32
+ function times(num1, num2) {
33
+ try {
34
+ var _num1 = Number(num1);
35
+ var _num2 = Number(num2);
36
+ return (isNaN(_num1) ? 0 : _num1) * (isNaN(_num2) ? 0 : _num2);
37
+ }
38
+ catch (err) {
39
+ console.error("计算乘法出错", err);
40
+ return 0;
41
+ }
42
+ }
43
+ /**
44
+ * 除法
45
+ */
46
+ function divide(num1, num2) {
47
+ try {
48
+ var _num1 = Number(num1);
49
+ var _num2 = Number(num2);
50
+ return (isNaN(_num1) ? 0 : _num1) / (isNaN(_num2) ? 0 : _num2);
51
+ }
52
+ catch (err) {
53
+ console.error("计算除法出错", err);
54
+ return 0;
55
+ }
56
+ }
57
+ /**
58
+ * 四舍五入保留小数
59
+ */
60
+ function exactRound(num, ratio) {
61
+ try {
62
+ return Number(num).toFixed(ratio);
63
+ }
64
+ catch (err) {
65
+ return num;
66
+ }
67
+ }
68
+ /**
69
+ * 将字节数加上合适的单位
70
+ * @param numBytes 字节数
71
+ * @returns
72
+ */
73
+ function formatUnit(numBytes) {
74
+ var _numBytes = Number(numBytes);
75
+ if (isNaN(_numBytes)) {
76
+ return numBytes;
77
+ }
78
+ var units = ["B", "KB", "MB", "GB", "TB"];
79
+ var unitIndex = 0;
80
+ while (_numBytes >= 1024 && unitIndex < units.length - 1) {
81
+ _numBytes /= 1024;
82
+ unitIndex++;
83
+ }
84
+ return _numBytes.toFixed(2) + units[unitIndex];
85
+ }
86
+
87
+ export { divide, exactRound, formatUnit, minus, plus, times };
@@ -15,7 +15,7 @@ function initMicroApp(render, microAppOptions) {
15
15
  return {};
16
16
  }
17
17
  // 2. 进入微前端环境的运行逻辑
18
- var microAppKey = microAppOptions.microAppKey, microAppRoot = microAppOptions.microAppRoot, microAppMountHandle = microAppOptions.microAppMountHandle, microAppUnMountHandle = microAppOptions.microAppUnMountHandle;
18
+ var microAppKey = microAppOptions.microAppKey; microAppOptions.microAppRoot; var microAppMountHandle = microAppOptions.microAppMountHandle, microAppUnMountHandle = microAppOptions.microAppUnMountHandle;
19
19
  // 唯一key没传 给出开发提示
20
20
  if (!microAppKey) {
21
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");
@@ -49,12 +49,10 @@ function initMicroApp(render, microAppOptions) {
49
49
  * 应用每次 切出/卸载 会调用的方法,通常在这里我们会卸载微应用的应用实例
50
50
  */
51
51
  function unmount(props) {
52
- var _a;
53
52
  return __awaiter(this, void 0, void 0, function () {
54
- return __generator(this, function (_b) {
55
- console.log("微应用 unmount");
53
+ return __generator(this, function (_a) {
54
+ console.log("微应用 unmount", props);
56
55
  microAppUnMountHandle && microAppUnMountHandle(props);
57
- (_a = microAppRoot === null || microAppRoot === void 0 ? void 0 : microAppRoot.unmount) === null || _a === void 0 ? void 0 : _a.call(microAppRoot);
58
56
  return [2 /*return*/];
59
57
  });
60
58
  });
@@ -0,0 +1,3 @@
1
+ function mitt(n){return {all:n=n||new Map,on:function(t,e){var i=n.get(t);i?i.push(e):n.set(t,[e]);},off:function(t,e){var i=n.get(t);i&&(e?i.splice(i.indexOf(e)>>>0,1):n.set(t,[]));},emit:function(t,e){var i=n.get(t);i&&i.slice().map(function(n){n(e);}),(i=n.get("*"))&&i.slice().map(function(n){n(t,e);});}}}
2
+
3
+ export { mitt as default };
@@ -0,0 +1,9 @@
1
+ declare function validatePassword(password: string, username: string): {
2
+ result: boolean;
3
+ message: string;
4
+ } | {
5
+ result: boolean;
6
+ message?: undefined;
7
+ };
8
+
9
+ export { validatePassword };