@gct-paas/core 0.1.4-dev.11 → 0.1.4-dev.12

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 (130) hide show
  1. package/dist/index.esm.min.js +21679 -0
  2. package/es/constants/core.mjs +5 -4
  3. package/es/constants/default-date-type/default-date-type.mjs +73 -21
  4. package/es/constants/editor-register/editor-register.mjs +17 -5
  5. package/es/constants/expression-type/BuiltOperators.mjs +152 -147
  6. package/es/constants/expression-type/FunctionKeys.mjs +75 -79
  7. package/es/constants/expression-type/editor.mjs +10 -3
  8. package/es/constants/expression-type/function.mjs +602 -613
  9. package/es/constants/expression-type/index.mjs +111 -113
  10. package/es/constants/expression-type/modeCfg.mjs +256 -263
  11. package/es/constants/expression-type/variable.mjs +43 -39
  12. package/es/constants/form-container-type/form-container-type.mjs +17 -5
  13. package/es/constants/index.mjs +30 -10
  14. package/es/constants/page-designer/model.mjs +15 -5
  15. package/es/create-app-vue.mjs +15 -9
  16. package/es/enums/app-designer/index.d.ts +19 -0
  17. package/es/enums/app-designer/index.mjs +131 -63
  18. package/es/enums/appEnum.mjs +681 -360
  19. package/es/enums/appStateEnum.mjs +17 -10
  20. package/es/enums/authActionEnum.mjs +63 -51
  21. package/es/enums/breakpointEnum.mjs +27 -26
  22. package/es/enums/cacheEnum.mjs +22 -21
  23. package/es/enums/designEnum.mjs +110 -71
  24. package/es/enums/developer-center/integration.mjs +7 -6
  25. package/es/enums/exceptionEnum.mjs +21 -17
  26. package/es/enums/expressionEnum.d.ts +1 -1
  27. package/es/enums/expressionEnum.mjs +81 -74
  28. package/es/enums/globalEnum.mjs +59 -36
  29. package/es/enums/httpEnum.mjs +71 -61
  30. package/es/enums/index.mjs +43 -14
  31. package/es/enums/menuEnum.mjs +42 -38
  32. package/es/enums/page-designer/designer.mjs +403 -407
  33. package/es/enums/page-designer/index.mjs +4 -0
  34. package/es/enums/page-designer/panel.mjs +341 -213
  35. package/es/enums/page-designer/toolkit.mjs +13 -12
  36. package/es/enums/page-designer/widget.mjs +425 -338
  37. package/es/enums/pageEnum.mjs +14 -13
  38. package/es/enums/plugin-enum.mjs +23 -7
  39. package/es/enums/processEnum.mjs +95 -60
  40. package/es/enums/roleEnum.mjs +7 -6
  41. package/es/enums/sizeEnum.d.ts +18 -0
  42. package/es/enums/sizeEnum.mjs +28 -8
  43. package/es/global/gct/gct.mjs +84 -96
  44. package/es/global/index.mjs +1 -0
  45. package/es/hooks/index.mjs +4 -0
  46. package/es/hooks/use-app-inst/use-app-inst.mjs +11 -5
  47. package/es/hooks/use-modal/use-modal.mjs +16 -10
  48. package/es/hooks/use-sub-app-utils/use-sub-app-utils.mjs +43 -23
  49. package/es/hooks/useCopyToClipboard.mjs +50 -50
  50. package/es/index.mjs +122 -114
  51. package/es/locale/index.mjs +43 -57
  52. package/es/modules/env-manager/env-manager.const.mjs +16 -8
  53. package/es/modules/env-manager/env-manager.interface.mjs +14 -7
  54. package/es/modules/env-manager/env-manager.mjs +104 -107
  55. package/es/modules/error-handler/error-handler.const.mjs +11 -16
  56. package/es/modules/error-handler/error-strategy.mjs +199 -175
  57. package/es/modules/error-handler/index.mjs +120 -106
  58. package/es/modules/mqtt/constants/mqtt.const.mjs +21 -24
  59. package/es/modules/mqtt/enums/mqtt-status.enum.mjs +23 -9
  60. package/es/modules/mqtt/index.mjs +4 -0
  61. package/es/modules/mqtt/mqtt-client.mjs +228 -261
  62. package/es/modules/mqtt/mqtt-manager.mjs +117 -77
  63. package/es/modules/platform-config/constants/index.mjs +4 -0
  64. package/es/modules/platform-config/constants/login.const.mjs +48 -45
  65. package/es/modules/platform-config/constants/org.const.mjs +57 -52
  66. package/es/modules/platform-config/constants/theme.const.mjs +11 -4
  67. package/es/modules/platform-config/constants/watermark.const.mjs +17 -12
  68. package/es/modules/platform-config/enums/deploy.enum.mjs +13 -6
  69. package/es/modules/platform-config/enums/login.enum.mjs +29 -15
  70. package/es/modules/platform-config/enums/platform.enum.mjs +16 -13
  71. package/es/modules/platform-config/index.mjs +9 -0
  72. package/es/modules/platform-config/store.mjs +68 -79
  73. package/es/modules/platform-config/useBasicSetting.mjs +47 -35
  74. package/es/modules/platform-config/useDeploySetting.mjs +29 -21
  75. package/es/modules/platform-config/useLoginSetting.mjs +151 -173
  76. package/es/modules/platform-config/useOrgSetting.mjs +63 -62
  77. package/es/modules/platform-config/useProjectSetting.mjs +14 -6
  78. package/es/modules/platform-config/useSecuritySetting.mjs +68 -56
  79. package/es/modules/platform-config/useThemeSetting.mjs +78 -59
  80. package/es/modules/platform-config/useWatermarkSetting.mjs +37 -23
  81. package/es/modules/user-stores/index.mjs +3 -0
  82. package/es/modules/user-stores/store/permission.store.mjs +27 -36
  83. package/es/modules/user-stores/store/tenant.store.mjs +20 -22
  84. package/es/modules/user-stores/store/user.store.mjs +94 -117
  85. package/es/router/index.mjs +25 -28
  86. package/es/setup-app.mjs +23 -39
  87. package/es/state/global-pinia-state/global-pinia-state.mjs +49 -71
  88. package/es/state/index.mjs +1 -0
  89. package/es/store/global-store.mjs +50 -72
  90. package/es/store/index.mjs +25 -19
  91. package/es/types/index.d.ts +7 -0
  92. package/es/utils/axios/interceptors.mjs +21 -17
  93. package/es/utils/cache-adapter/cache-adapter.mjs +61 -56
  94. package/es/utils/design/design.mjs +18 -12
  95. package/es/utils/deviceFingerprint.mjs +74 -63
  96. package/es/utils/dictionary/dictionary.mjs +142 -145
  97. package/es/utils/file/base64Conver.mjs +35 -30
  98. package/es/utils/file/download.mjs +94 -98
  99. package/es/utils/file/parser.d.ts +3 -0
  100. package/es/utils/file/parser.mjs +29 -0
  101. package/es/utils/i18n/index.mjs +14 -3
  102. package/es/utils/index.d.ts +1 -0
  103. package/es/utils/index.mjs +31 -0
  104. package/es/utils/is-sort-filed/is-sort-filed.mjs +42 -37
  105. package/es/utils/linked-list/linked-list.mjs +115 -118
  106. package/es/utils/linked-node/linked-node.mjs +41 -31
  107. package/es/utils/lowcode/utils.mjs +13 -18
  108. package/es/utils/lowcode/validate.mjs +20 -26
  109. package/es/utils/mitt/mitt.mjs +4 -4
  110. package/es/utils/model-loader/model-loader.mjs +280 -325
  111. package/es/utils/namespace/namespace.mjs +178 -164
  112. package/es/utils/openUtil/index.mjs +2 -0
  113. package/es/utils/openUtil/modal/modal.mjs +72 -79
  114. package/es/utils/openUtil/overlay-container/overlay-container.mjs +144 -138
  115. package/es/utils/permission.mjs +33 -37
  116. package/es/utils/plugin-static-resource/plugin-static-resource.mjs +46 -42
  117. package/es/utils/style/index.mjs +94 -138
  118. package/es/utils/tools/tools.mjs +86 -54
  119. package/es/utils/treeHelper/treeHelper.mjs +205 -233
  120. package/es/utils/uploader/uploader.mjs +81 -115
  121. package/es/utils/useUUid.mjs +79 -87
  122. package/es/utils/util.mjs +55 -35
  123. package/es/utils/uuid/uuid.d.ts +1 -0
  124. package/es/utils/uuid/uuid.mjs +36 -43
  125. package/es/utils/validate.mjs +15 -19
  126. package/es/utils/value-helper/value-helper.mjs +113 -98
  127. package/package.json +12 -13
  128. package/dist/index.esm.min.mjs +0 -18322
  129. package/dist/index.min.cjs +0 -393
  130. package/dist/index.system.min.js +0 -393
@@ -1,20 +1,24 @@
1
- import { AxiosHeaders } from 'axios';
2
- import { getTimezone, getTenant, isMobile, getToken } from '../tools/tools.mjs';
3
-
1
+ import { getTenant, getTimezone, getToken, isMobile } from "../tools/tools.mjs";
2
+ import { AxiosHeaders } from "axios";
3
+ //#region src/utils/axios/interceptors.ts
4
+ /**
5
+ * 安装拦截器
6
+ *
7
+ * @export
8
+ * @param {AxiosInstance} axios
9
+ */
4
10
  function interceptors(axios) {
5
- axios.interceptors.request.use((config) => {
6
- if (!config.headers) {
7
- config.headers = new AxiosHeaders();
8
- }
9
- Object.assign(config.headers, {
10
- Token: getToken(),
11
- Source: isMobile ? 502 : 501,
12
- Lang: _gct.store.lang,
13
- "Tenant-Id": getTenant(),
14
- Timezone: getTimezone()
15
- });
16
- return config;
17
- });
11
+ axios.interceptors.request.use((config) => {
12
+ if (!config.headers) config.headers = new AxiosHeaders();
13
+ Object.assign(config.headers, {
14
+ Token: getToken(),
15
+ Source: isMobile ? 502 : 501,
16
+ Lang: _gct.store.lang,
17
+ "Tenant-Id": getTenant(),
18
+ Timezone: getTimezone()
19
+ });
20
+ return config;
21
+ });
18
22
  }
19
-
23
+ //#endregion
20
24
  export { interceptors };
@@ -1,59 +1,64 @@
1
- import qs from 'qs';
2
-
3
- const gctMemoizeAsync = (...arg) => cacheAdapter.bind(null, ...arg);
1
+ import qs from "qs";
2
+ //#region src/utils/cache-adapter/cache-adapter.ts
3
+ /**异步缓存函数 */
4
+ var gctMemoizeAsync = (...arg) => cacheAdapter.bind(null, ...arg);
5
+ /**
6
+ *异步缓存
7
+ * @param args
8
+ * @param adapter
9
+ * @returns
10
+ */
4
11
  function cacheAdapter(adapter, ...args) {
5
- const maxAge = 1e3 * 60 * 5;
6
- const requestKey = typeof args === "object" ? qs.stringify(args) : args;
7
- let responsePromise = MemoryCache.get(requestKey);
8
- if (!responsePromise) {
9
- responsePromise = (async () => {
10
- try {
11
- return await adapter(...args);
12
- } catch (reason) {
13
- MemoryCache.delete(requestKey);
14
- throw reason;
15
- }
16
- })();
17
- MemoryCache.set(requestKey, responsePromise, maxAge);
18
- return responsePromise;
19
- }
20
- return responsePromise;
12
+ /**默认缓存5分钟 */
13
+ const maxAge = 1e3 * 60 * 5;
14
+ const requestKey = typeof args === "object" ? qs.stringify(args) : args;
15
+ let responsePromise = MemoryCache.get(requestKey);
16
+ if (!responsePromise) {
17
+ responsePromise = (async () => {
18
+ try {
19
+ return await adapter(...args);
20
+ } catch (reason) {
21
+ MemoryCache.delete(requestKey);
22
+ throw reason;
23
+ }
24
+ })();
25
+ MemoryCache.set(requestKey, responsePromise, maxAge);
26
+ return responsePromise;
27
+ }
28
+ return responsePromise;
21
29
  }
22
- class MemoryCache {
23
- static cachedata = {};
24
- static set(key, value, maxAge) {
25
- this.cachedata[key] = {
26
- maxAge: maxAge || 0,
27
- value,
28
- now: Date.now()
29
- };
30
- }
31
- static get(key) {
32
- this.reset();
33
- const cachedItem = this.cachedata[key];
34
- if (!cachedItem) return null;
35
- return cachedItem.value;
36
- }
37
- static delete(key) {
38
- return delete this.cachedata[key];
39
- }
40
- static clear() {
41
- this.cachedata = {};
42
- }
43
- /**
44
- *清空过期的数据
45
- */
46
- static reset() {
47
- for (const key in this.cachedata) {
48
- const cachedItem = this.cachedata[key];
49
- if (cachedItem) {
50
- const isExpired = Date.now() - cachedItem.now > cachedItem.maxAge;
51
- if (isExpired) {
52
- this.delete(key);
53
- }
54
- }
55
- }
56
- }
57
- }
58
-
30
+ var MemoryCache = class {
31
+ static cachedata = {};
32
+ static set(key, value, maxAge) {
33
+ this.cachedata[key] = {
34
+ maxAge: maxAge || 0,
35
+ value,
36
+ now: Date.now()
37
+ };
38
+ }
39
+ static get(key) {
40
+ this.reset();
41
+ const cachedItem = this.cachedata[key];
42
+ if (!cachedItem) return null;
43
+ return cachedItem.value;
44
+ }
45
+ static delete(key) {
46
+ return delete this.cachedata[key];
47
+ }
48
+ static clear() {
49
+ this.cachedata = {};
50
+ }
51
+ /**
52
+ *清空过期的数据
53
+ */
54
+ static reset() {
55
+ for (const key in this.cachedata) {
56
+ const cachedItem = this.cachedata[key];
57
+ if (cachedItem) {
58
+ if (Date.now() - cachedItem.now > cachedItem.maxAge) this.delete(key);
59
+ }
60
+ }
61
+ }
62
+ };
63
+ //#endregion
59
64
  export { gctMemoizeAsync };
@@ -1,15 +1,21 @@
1
- import { intersection } from 'lodash-es';
2
- import '../../enums/app-designer/index.mjs';
3
- import '../../enums/page-designer/designer.mjs';
4
- import '../../enums/breakpointEnum.mjs';
5
- import { notSingleArr } from '../../enums/designEnum.mjs';
6
-
1
+ import { notSingleArr } from "../../enums/designEnum.mjs";
2
+ import "../../enums/index.mjs";
3
+ import { intersection } from "lodash-es";
4
+ //#region src/utils/design/design.ts
5
+ /**
6
+ * 是否完全为多选算子
7
+ *
8
+ * @description 只有全部是多选算子时,下拉才可以算是多选
9
+ * @author zhanghanrui
10
+ * @date 2024-09-20 11:09:47
11
+ * @export
12
+ * @param {string[]} arr
13
+ * @return {*} {boolean}
14
+ */
7
15
  function isMultipleOperator(arr) {
8
- const items = intersection(arr, notSingleArr);
9
- if (items.length > 0 && items.length === arr.length) {
10
- return true;
11
- }
12
- return false;
16
+ const items = intersection(arr, notSingleArr);
17
+ if (items.length > 0 && items.length === arr.length) return true;
18
+ return false;
13
19
  }
14
-
20
+ //#endregion
15
21
  export { isMultipleOperator };
@@ -1,73 +1,84 @@
1
- import FingerprintJS from '@fingerprintjs/fingerprintjs';
2
-
3
- const FINGERPRINT_KEY = "FINGERPRINT";
1
+ import FingerprintJS from "@fingerprintjs/fingerprintjs";
2
+ //#region src/utils/deviceFingerprint.ts
3
+ /** 指纹缓存 key */
4
+ var FINGERPRINT_KEY = "FINGERPRINT";
5
+ /** 判断是否浏览器环境 */
4
6
  function isBrowserEnv() {
5
- return typeof window !== "undefined" && typeof navigator !== "undefined";
7
+ return typeof window !== "undefined" && typeof navigator !== "undefined";
6
8
  }
9
+ /** 获取客户端平台(浏览器 / 移动系统) */
7
10
  function getClientPlatform() {
8
- if (!isBrowserEnv()) {
9
- return { type: "unknown", name: "unknown" };
10
- }
11
- const ua = navigator.userAgent;
12
- if (/iPad|iPhone|iPod/i.test(ua)) {
13
- return { type: "mobile", name: "iOS" };
14
- }
15
- if (/Android/i.test(ua)) {
16
- return { type: "mobile", name: "Android" };
17
- }
18
- if (/Windows Phone/i.test(ua)) {
19
- return { type: "mobile", name: "Windows Phone" };
20
- }
21
- if (/BlackBerry/i.test(ua)) {
22
- return { type: "mobile", name: "BlackBerry" };
23
- }
24
- if (/Edg/i.test(ua)) {
25
- return { type: "web", name: "Edge" };
26
- }
27
- if (/OPR|Opera/i.test(ua)) {
28
- return { type: "web", name: "Opera" };
29
- }
30
- if (/Firefox/i.test(ua)) {
31
- return { type: "web", name: "Firefox" };
32
- }
33
- if (/Chrome/i.test(ua)) {
34
- return { type: "web", name: "Chrome" };
35
- }
36
- if (/Safari/i.test(ua)) {
37
- return { type: "web", name: "Safari" };
38
- }
39
- return { type: "unknown", name: "unknown" };
11
+ if (!isBrowserEnv()) return {
12
+ type: "unknown",
13
+ name: "unknown"
14
+ };
15
+ const ua = navigator.userAgent;
16
+ if (/iPad|iPhone|iPod/i.test(ua)) return {
17
+ type: "mobile",
18
+ name: "iOS"
19
+ };
20
+ if (/Android/i.test(ua)) return {
21
+ type: "mobile",
22
+ name: "Android"
23
+ };
24
+ if (/Windows Phone/i.test(ua)) return {
25
+ type: "mobile",
26
+ name: "Windows Phone"
27
+ };
28
+ if (/BlackBerry/i.test(ua)) return {
29
+ type: "mobile",
30
+ name: "BlackBerry"
31
+ };
32
+ if (/Edg/i.test(ua)) return {
33
+ type: "web",
34
+ name: "Edge"
35
+ };
36
+ if (/OPR|Opera/i.test(ua)) return {
37
+ type: "web",
38
+ name: "Opera"
39
+ };
40
+ if (/Firefox/i.test(ua)) return {
41
+ type: "web",
42
+ name: "Firefox"
43
+ };
44
+ if (/Chrome/i.test(ua)) return {
45
+ type: "web",
46
+ name: "Chrome"
47
+ };
48
+ if (/Safari/i.test(ua)) return {
49
+ type: "web",
50
+ name: "Safari"
51
+ };
52
+ return {
53
+ type: "unknown",
54
+ name: "unknown"
55
+ };
40
56
  }
57
+ /** 获取浏览器指纹对象 */
41
58
  async function getFingerprint() {
42
- const agent = await FingerprintJS.load();
43
- return agent.get();
59
+ return (await FingerprintJS.load()).get();
44
60
  }
61
+ /** 获取设备指纹标识(统一入口) */
45
62
  async function getDeviceFingerprint() {
46
- if (!isBrowserEnv()) {
47
- return "unknown/unknown";
48
- }
49
- const { type, name } = getClientPlatform();
50
- const isWeb = type === "web";
51
- if (isWeb) {
52
- const cached = localStorage.getItem(FINGERPRINT_KEY);
53
- if (cached) {
54
- return `${name}/${cached}`;
55
- }
56
- }
57
- const fingerprint = await getFingerprint();
58
- const visitorId = fingerprint.visitorId;
59
- if (isWeb) {
60
- localStorage.setItem(FINGERPRINT_KEY, visitorId);
61
- }
62
- return `${name}/${visitorId}`;
63
+ if (!isBrowserEnv()) return "unknown/unknown";
64
+ const { type, name } = getClientPlatform();
65
+ const isWeb = type === "web";
66
+ if (isWeb) {
67
+ const cached = localStorage.getItem(FINGERPRINT_KEY);
68
+ if (cached) return `${name}/${cached}`;
69
+ }
70
+ const visitorId = (await getFingerprint()).visitorId;
71
+ if (isWeb) localStorage.setItem(FINGERPRINT_KEY, visitorId);
72
+ return `${name}/${visitorId}`;
63
73
  }
74
+ /** 页签唯一标识 */
64
75
  function getPageIdentification() {
65
- let pageTag = sessionStorage.getItem("currentPageTag");
66
- if (!pageTag) {
67
- pageTag = Date.now().toString();
68
- sessionStorage.setItem("currentPageTag", pageTag);
69
- }
70
- return pageTag;
76
+ let pageTag = sessionStorage.getItem("currentPageTag");
77
+ if (!pageTag) {
78
+ pageTag = Date.now().toString();
79
+ sessionStorage.setItem("currentPageTag", pageTag);
80
+ }
81
+ return pageTag;
71
82
  }
72
-
73
- export { getClientPlatform, getDeviceFingerprint, getFingerprint, getPageIdentification };
83
+ //#endregion
84
+ export { getDeviceFingerprint, getPageIdentification };
@@ -1,146 +1,143 @@
1
- class DictionaryUtil {
2
- /**
3
- * 代码表配置
4
- *
5
- * @author zhanghanrui
6
- * @date 2024-03-27 13:03:59
7
- * @private
8
- * @type {Map<string, IDictionary>}
9
- */
10
- configs = /* @__PURE__ */ new Map();
11
- /**
12
- * 已经加载的代码表缓存
13
- *
14
- * @author zhanghanrui
15
- * @date 2024-03-27 13:03:14
16
- * @private
17
- * @type {Map<string, IDictionaryItem[]>}
18
- */
19
- cache = /* @__PURE__ */ new Map();
20
- /**
21
- * 获取代码表配置
22
- *
23
- * @author zhanghanrui
24
- * @date 2024-04-02 13:04:32
25
- * @param {string} tag
26
- * @return {*} {(IDictionary | undefined)}
27
- */
28
- getConfig(tag) {
29
- return this.configs.get(tag);
30
- }
31
- /**
32
- * 注册写的代码表配置
33
- *
34
- * @author zhanghanrui
35
- * @date 2024-03-27 13:03:17
36
- * @param {IDictionary} config
37
- */
38
- register(config) {
39
- this.configs.set(config.tag, config);
40
- if (config.items) {
41
- this.cache.set(config.tag, config.items);
42
- }
43
- }
44
- /**
45
- * 取消注册代码表
46
- *
47
- * @author zhanghanrui
48
- * @date 2024-03-27 13:03:58
49
- * @param {string} tag
50
- */
51
- unregister(tag) {
52
- this.configs.delete(tag);
53
- this.cache.delete(tag);
54
- }
55
- /**
56
- * 获取代码表配置
57
- *
58
- * @author zhanghanrui
59
- * @date 2024-03-27 13:03:06
60
- * @param {string} codeTag
61
- * @return {*} {IDictionaryItem[]}
62
- */
63
- get(codeTag) {
64
- return this.cache.get(codeTag) || [];
65
- }
66
- /**
67
- * 动态请求代码表
68
- *
69
- * @author zhanghanrui
70
- * @date 2024-03-27 13:03:14
71
- * @param {string} codeTag
72
- * @param {IParams} [params]
73
- * @return {*} {Promise<IDictionaryItem[]>}
74
- */
75
- async asyncGet(codeTag, params) {
76
- const config = this.configs.get(codeTag);
77
- if (!config) {
78
- return [];
79
- }
80
- if (config.mode === "static") {
81
- return this.getByConfig(config);
82
- }
83
- if (config.mode === "async") {
84
- if (this.cache.has(codeTag)) {
85
- return this.cache.get(codeTag) || [];
86
- }
87
- return this.asyncGetByConfig(config, params);
88
- }
89
- return [];
90
- }
91
- /**
92
- * 根据配置获取代码表
93
- *
94
- * @author zhanghanrui
95
- * @date 2024-04-02 21:04:25
96
- * @param {IDictionary} config
97
- * @return {*} {IDictionaryItem[]}
98
- */
99
- getByConfig(config) {
100
- return config.items || [];
101
- }
102
- /**
103
- * 根据配置获取异步代码表
104
- *
105
- * @author zhanghanrui
106
- * @date 2024-04-02 21:04:00
107
- * @param {IDictionary} config
108
- * @param {IParams} [params={}]
109
- * @return {*} {Promise<IDictionaryItem[]>}
110
- */
111
- async asyncGetByConfig(config, params = {}) {
112
- if (config.fetch) {
113
- const items = await config.fetch(params || {});
114
- if (items) {
115
- const [key, value] = config.keys || ["name", "id"];
116
- return this.deepFormat(items, key, value);
117
- }
118
- }
119
- return [];
120
- }
121
- /**
122
- * 递归格式化代码表
123
- *
124
- * @author zhanghanrui
125
- * @date 2024-04-02 22:04:03
126
- * @protected
127
- * @param {IData[]} items
128
- * @param {string} key
129
- * @param {string} value
130
- * @return {*} {IDictionaryItem[]}
131
- */
132
- deepFormat(items, key, value) {
133
- return items.map((item) => {
134
- const config = {
135
- label: item[key],
136
- value: item[value]
137
- };
138
- if (item.children && item.children.length > 0) {
139
- config.options = this.deepFormat(item.children, key, value);
140
- }
141
- return config;
142
- });
143
- }
144
- }
145
-
1
+ //#region src/utils/dictionary/dictionary.ts
2
+ /**
3
+ * 数据字典工具类
4
+ *
5
+ * @export
6
+ * @class DictionaryService
7
+ */
8
+ var DictionaryUtil = class {
9
+ /**
10
+ * 代码表配置
11
+ *
12
+ * @author zhanghanrui
13
+ * @date 2024-03-27 13:03:59
14
+ * @private
15
+ * @type {Map<string, IDictionary>}
16
+ */
17
+ configs = /* @__PURE__ */ new Map();
18
+ /**
19
+ * 已经加载的代码表缓存
20
+ *
21
+ * @author zhanghanrui
22
+ * @date 2024-03-27 13:03:14
23
+ * @private
24
+ * @type {Map<string, IDictionaryItem[]>}
25
+ */
26
+ cache = /* @__PURE__ */ new Map();
27
+ /**
28
+ * 获取代码表配置
29
+ *
30
+ * @author zhanghanrui
31
+ * @date 2024-04-02 13:04:32
32
+ * @param {string} tag
33
+ * @return {*} {(IDictionary | undefined)}
34
+ */
35
+ getConfig(tag) {
36
+ return this.configs.get(tag);
37
+ }
38
+ /**
39
+ * 注册写的代码表配置
40
+ *
41
+ * @author zhanghanrui
42
+ * @date 2024-03-27 13:03:17
43
+ * @param {IDictionary} config
44
+ */
45
+ register(config) {
46
+ this.configs.set(config.tag, config);
47
+ if (config.items) this.cache.set(config.tag, config.items);
48
+ }
49
+ /**
50
+ * 取消注册代码表
51
+ *
52
+ * @author zhanghanrui
53
+ * @date 2024-03-27 13:03:58
54
+ * @param {string} tag
55
+ */
56
+ unregister(tag) {
57
+ this.configs.delete(tag);
58
+ this.cache.delete(tag);
59
+ }
60
+ /**
61
+ * 获取代码表配置
62
+ *
63
+ * @author zhanghanrui
64
+ * @date 2024-03-27 13:03:06
65
+ * @param {string} codeTag
66
+ * @return {*} {IDictionaryItem[]}
67
+ */
68
+ get(codeTag) {
69
+ return this.cache.get(codeTag) || [];
70
+ }
71
+ /**
72
+ * 动态请求代码表
73
+ *
74
+ * @author zhanghanrui
75
+ * @date 2024-03-27 13:03:14
76
+ * @param {string} codeTag
77
+ * @param {IParams} [params]
78
+ * @return {*} {Promise<IDictionaryItem[]>}
79
+ */
80
+ async asyncGet(codeTag, params) {
81
+ const config = this.configs.get(codeTag);
82
+ if (!config) return [];
83
+ if (config.mode === "static") return this.getByConfig(config);
84
+ if (config.mode === "async") {
85
+ if (this.cache.has(codeTag)) return this.cache.get(codeTag) || [];
86
+ return this.asyncGetByConfig(config, params);
87
+ }
88
+ return [];
89
+ }
90
+ /**
91
+ * 根据配置获取代码表
92
+ *
93
+ * @author zhanghanrui
94
+ * @date 2024-04-02 21:04:25
95
+ * @param {IDictionary} config
96
+ * @return {*} {IDictionaryItem[]}
97
+ */
98
+ getByConfig(config) {
99
+ return config.items || [];
100
+ }
101
+ /**
102
+ * 根据配置获取异步代码表
103
+ *
104
+ * @author zhanghanrui
105
+ * @date 2024-04-02 21:04:00
106
+ * @param {IDictionary} config
107
+ * @param {IParams} [params={}]
108
+ * @return {*} {Promise<IDictionaryItem[]>}
109
+ */
110
+ async asyncGetByConfig(config, params = {}) {
111
+ if (config.fetch) {
112
+ const items = await config.fetch(params || {});
113
+ if (items) {
114
+ const [key, value] = config.keys || ["name", "id"];
115
+ return this.deepFormat(items, key, value);
116
+ }
117
+ }
118
+ return [];
119
+ }
120
+ /**
121
+ * 递归格式化代码表
122
+ *
123
+ * @author zhanghanrui
124
+ * @date 2024-04-02 22:04:03
125
+ * @protected
126
+ * @param {IData[]} items
127
+ * @param {string} key
128
+ * @param {string} value
129
+ * @return {*} {IDictionaryItem[]}
130
+ */
131
+ deepFormat(items, key, value) {
132
+ return items.map((item) => {
133
+ const config = {
134
+ label: item[key],
135
+ value: item[value]
136
+ };
137
+ if (item.children && item.children.length > 0) config.options = this.deepFormat(item.children, key, value);
138
+ return config;
139
+ });
140
+ }
141
+ };
142
+ //#endregion
146
143
  export { DictionaryUtil };