@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,326 +1,281 @@
1
- import { cloneDeep } from 'lodash-es';
2
- import { EntityModelCategoryEnum } from '../../enums/app-designer/index.mjs';
3
- import '../../enums/page-designer/designer.mjs';
4
- import '../../enums/breakpointEnum.mjs';
5
-
6
- class ModelLoader {
7
- // 缓存过期时间(毫秒),默认10分钟
8
- CACHE_EXPIRATION_TIME = 10 * 60 * 1e3;
9
- modelCache = /* @__PURE__ */ new Map();
10
- modelLoadingCache = /* @__PURE__ */ new Map();
11
- modelsLoadingCache = /* @__PURE__ */ new Map();
12
- enumCache = /* @__PURE__ */ new Map();
13
- enumLoadingCache = /* @__PURE__ */ new Map();
14
- queryRefDataCache = /* @__PURE__ */ new Map();
15
- queryRefDataLoadingCache = /* @__PURE__ */ new Map();
16
- /**
17
- * 检查缓存条目是否过期
18
- *
19
- * @param {CacheEntry<any>} entry
20
- * @returns {*} {boolean}
21
- */
22
- isExpired(entry) {
23
- return Date.now() > entry.expiresAt;
24
- }
25
- /**
26
- * 创建缓存条目
27
- *
28
- * @param {T} data
29
- * @returns {*} {CacheEntry<T>}
30
- */
31
- createCacheEntry(data) {
32
- return {
33
- data,
34
- expiresAt: Date.now() + this.CACHE_EXPIRATION_TIME
35
- };
36
- }
37
- /**
38
- * 加载模型信息,具有缓存和请求去重功能
39
- *
40
- * @author chitanda
41
- * @date 2025-06-20 16:06:05
42
- * @param {string} modelKey
43
- * @returns {*} {Promise<ModelMetaDTO>}
44
- */
45
- async loadModel(modelKey) {
46
- if (this.modelCache.has(modelKey)) {
47
- const cacheEntry = this.modelCache.get(modelKey);
48
- if (!this.isExpired(cacheEntry)) {
49
- return cacheEntry.data;
50
- }
51
- this.modelCache.delete(modelKey);
52
- }
53
- if (this.modelLoadingCache.has(modelKey)) {
54
- return this.modelLoadingCache.get(modelKey);
55
- }
56
- const loadPromise = (async () => {
57
- try {
58
- const data = await _api.apaas.modelMeta.getDetail({ modelKey });
59
- if (data) {
60
- this.modelCache.set(modelKey, this.createCacheEntry(data));
61
- return data;
62
- }
63
- return {};
64
- } finally {
65
- this.modelLoadingCache.delete(modelKey);
66
- }
67
- })();
68
- this.modelLoadingCache.set(modelKey, loadPromise);
69
- return loadPromise;
70
- }
71
- /**
72
- * 加载多个模型信息
73
- *
74
- * @author chitanda
75
- * @date 2025-06-22 15:06:54
76
- * @param {string[]} modelKeys
77
- * @returns {*} {Promise<ModelMetaDTO[]>}
78
- */
79
- async loadModels(modelKeys) {
80
- const cacheKey = modelKeys.join(",");
81
- const allCached = modelKeys.every((key) => {
82
- const entry = this.modelCache.get(key);
83
- return entry && !this.isExpired(entry);
84
- });
85
- if (allCached) {
86
- return modelKeys.map((key) => this.modelCache.get(key).data);
87
- }
88
- modelKeys.forEach((key) => {
89
- const entry = this.modelCache.get(key);
90
- if (entry && this.isExpired(entry)) {
91
- this.modelCache.delete(key);
92
- }
93
- });
94
- if (this.modelsLoadingCache.has(cacheKey)) {
95
- return this.modelsLoadingCache.get(cacheKey);
96
- }
97
- const loadPromise = (async () => {
98
- try {
99
- const pendingKeys = modelKeys.filter((key) => !this.modelCache.has(key));
100
- if (pendingKeys.length > 0) {
101
- const data = await _api.apaas.modelMeta.getByKeys({
102
- modelKeys: pendingKeys.join(",")
103
- });
104
- if (data && data.length > 0) {
105
- data.forEach((model) => {
106
- this.modelCache.set(model.key, this.createCacheEntry(model));
107
- model.fieldMetaList = model.fieldMetas || [];
108
- });
109
- }
110
- }
111
- return modelKeys.map((key) => {
112
- const entry = this.modelCache.get(key);
113
- return entry.data;
114
- });
115
- } finally {
116
- this.modelsLoadingCache.delete(cacheKey);
117
- }
118
- })();
119
- this.modelsLoadingCache.set(cacheKey, loadPromise);
120
- return loadPromise;
121
- }
122
- /**
123
- * 加载指定模型的字段信息
124
- *
125
- * @author chitanda
126
- * @date 2025-06-22 14:06:37
127
- * @param {string} modelKey
128
- * @param {string} fieldKey
129
- * @returns {*} {(Promise<FieldMetaDTO | undefined>)}
130
- */
131
- async loadField(modelKey, fieldKey) {
132
- const model = await this.loadModel(modelKey);
133
- if (model?.fieldMetaList) {
134
- return model.fieldMetaList.find((field) => field.key === fieldKey);
135
- }
136
- return void 0;
137
- }
138
- /**
139
- * 加载指定模型的字段路径信息
140
- *
141
- * @author chitanda
142
- * @date 2025-06-22 14:06:11
143
- * @param {string} modelKey
144
- * @param {string} fieldKey
145
- * @returns {*} {Promise<string[]>}
146
- */
147
- async loadFieldPaths(modelKey, fieldKey, fieldCodeChain) {
148
- if (!fieldCodeChain) {
149
- return [];
150
- }
151
- const list = [];
152
- const isFieldModel = !!fieldCodeChain.bindFieldKey;
153
- const modelKeys = isFieldModel ? fieldCodeChain.modelLink || [
154
- fieldCodeChain.belongModelKey,
155
- fieldCodeChain.bindModelKey
156
- ] : [fieldCodeChain.modelKey];
157
- const models = await this.loadModels(modelKeys);
158
- if (isFieldModel) {
159
- list.push(...models.map((model2) => model2.name));
160
- } else {
161
- const model2 = await this.loadModel(fieldCodeChain.modelKey);
162
- if (model2) {
163
- list.push(model2.name);
164
- }
165
- }
166
- const model = await this.loadModel(modelKey);
167
- if (model?.fieldMetaList) {
168
- const field = model.fieldMetaList.find((field2) => field2.key === fieldKey);
169
- if (field) {
170
- list.push(field.name);
171
- }
172
- }
173
- return list;
174
- }
175
- /**
176
- * 加载指定模型的枚举列表
177
- *
178
- * @param {string} modelKey
179
- * @param {string} fieldKey
180
- * @param {string} [modelCategory=EntityModelCategoryEnum.ENTITY]
181
- * @returns {*} {Promise<IObject[]>}
182
- */
183
- async loadEnumList(modelKey, fieldKey, modelCategory = EntityModelCategoryEnum.ENTITY) {
184
- const cacheKey = `${modelCategory}:${modelKey}:${fieldKey}`;
185
- if (this.enumCache.has(cacheKey)) {
186
- const cacheEntry = this.enumCache.get(cacheKey);
187
- if (!this.isExpired(cacheEntry)) {
188
- return cloneDeep(cacheEntry.data);
189
- }
190
- this.enumCache.delete(cacheKey);
191
- this.enumLoadingCache.delete(cacheKey);
192
- }
193
- if (this.enumLoadingCache.has(cacheKey)) {
194
- return this.enumLoadingCache.get(cacheKey);
195
- }
196
- const loadPromise = (async () => {
197
- try {
198
- return [];
199
- } finally {
200
- this.enumLoadingCache.delete(cacheKey);
201
- }
202
- })();
203
- this.enumLoadingCache.set(cacheKey, loadPromise);
204
- return loadPromise;
205
- }
206
- /**
207
- * 加载关联数据查询(QueryRef)
208
- *
209
- * @param {QueryRefDataRequest} request
210
- * @returns {*} {Promise<ModelPageableRow>}
211
- */
212
- async loadQueryRefData(request) {
213
- if (!request || !request.modelKey) {
214
- throw new Error(`queryRefData 参数缺失`);
215
- }
216
- const cacheKey = JSON.stringify(request);
217
- if (this.queryRefDataCache.has(cacheKey)) {
218
- const cacheEntry = this.queryRefDataCache.get(cacheKey);
219
- if (!this.isExpired(cacheEntry)) {
220
- return cloneDeep(cacheEntry.data);
221
- }
222
- this.queryRefDataCache.delete(cacheKey);
223
- this.queryRefDataLoadingCache.delete(cacheKey);
224
- }
225
- if (this.queryRefDataLoadingCache.has(cacheKey)) {
226
- return this.queryRefDataLoadingCache.get(cacheKey);
227
- }
228
- const loadPromise = (async () => {
229
- try {
230
- const data = await _api.apaas.modelData.postQueryRefData(request);
231
- if (data) {
232
- this.queryRefDataCache.set(cacheKey, this.createCacheEntry(data));
233
- return cloneDeep(data);
234
- }
235
- return {};
236
- } finally {
237
- this.queryRefDataLoadingCache.delete(cacheKey);
238
- }
239
- })();
240
- this.queryRefDataLoadingCache.set(cacheKey, loadPromise);
241
- return loadPromise;
242
- }
243
- /**
244
- * 获取已缓存的模型
245
- * @param modelKey 模型键
246
- * @returns ModelMetaDTO | undefined
247
- */
248
- getCachedModel(modelKey) {
249
- const entry = this.modelCache.get(modelKey);
250
- if (entry && !this.isExpired(entry)) {
251
- return entry.data;
252
- }
253
- if (entry && this.isExpired(entry)) {
254
- this.modelCache.delete(modelKey);
255
- }
256
- return void 0;
257
- }
258
- /**
259
- * 清除指定模型的缓存
260
- *
261
- * @author chitanda
262
- * @date 2025-06-20 16:06:41
263
- * @param {string} modelKey
264
- */
265
- clear(modelKey) {
266
- this.modelCache.delete(modelKey);
267
- this.modelLoadingCache.delete(modelKey);
268
- const keysToDelete = [];
269
- this.modelsLoadingCache.forEach((_, cacheKey) => {
270
- if (cacheKey.includes(modelKey)) {
271
- keysToDelete.push(cacheKey);
272
- }
273
- });
274
- keysToDelete.forEach((key) => {
275
- this.modelsLoadingCache.delete(key);
276
- });
277
- const enumKeysToDelete = [];
278
- this.enumCache.forEach((_, cacheKey) => {
279
- if (cacheKey.includes(modelKey)) {
280
- enumKeysToDelete.push(cacheKey);
281
- }
282
- });
283
- enumKeysToDelete.forEach((key) => {
284
- this.enumCache.delete(key);
285
- this.enumLoadingCache.delete(key);
286
- });
287
- const queryRefKeysToDelete = [];
288
- this.queryRefDataCache.forEach((_, cacheKey) => {
289
- if (cacheKey.includes(`"modelKey":"${modelKey}"`)) {
290
- queryRefKeysToDelete.push(cacheKey);
291
- }
292
- });
293
- queryRefKeysToDelete.forEach((key) => {
294
- this.queryRefDataCache.delete(key);
295
- this.queryRefDataLoadingCache.delete(key);
296
- });
297
- }
298
- /**
299
- * 清除所有模型缓存
300
- *
301
- * @author chitanda
302
- * @date 2025-06-20 16:06:35
303
- */
304
- clearAll() {
305
- this.modelCache.clear();
306
- this.modelLoadingCache.clear();
307
- this.modelsLoadingCache.clear();
308
- this.enumCache.clear();
309
- this.enumLoadingCache.clear();
310
- this.queryRefDataCache.clear();
311
- this.queryRefDataLoadingCache.clear();
312
- }
313
- /**
314
- * 获取所有已缓存的模型键
315
- *
316
- * @author chitanda
317
- * @date 2025-06-20 16:06:55
318
- * @returns {*} {string[]}
319
- */
320
- keys() {
321
- return Array.from(this.modelCache.keys());
322
- }
323
- }
324
- const modelLoader = new ModelLoader();
325
-
1
+ import { EntityModelCategoryEnum } from "../../enums/app-designer/index.mjs";
2
+ import "../../enums/index.mjs";
3
+ import { cloneDeep } from "lodash-es";
4
+ //#region src/utils/model-loader/model-loader.ts
5
+ /**
6
+ * 模型加载器,提供模型缓存和请求去重功能
7
+ *
8
+ * @author chitanda
9
+ * @date 2025-06-20 16:06:12
10
+ * @class ModelLoader
11
+ */
12
+ var ModelLoader = class {
13
+ CACHE_EXPIRATION_TIME = 600 * 1e3;
14
+ modelCache = /* @__PURE__ */ new Map();
15
+ modelLoadingCache = /* @__PURE__ */ new Map();
16
+ modelsLoadingCache = /* @__PURE__ */ new Map();
17
+ enumCache = /* @__PURE__ */ new Map();
18
+ enumLoadingCache = /* @__PURE__ */ new Map();
19
+ queryRefDataCache = /* @__PURE__ */ new Map();
20
+ queryRefDataLoadingCache = /* @__PURE__ */ new Map();
21
+ /**
22
+ * 检查缓存条目是否过期
23
+ *
24
+ * @param {CacheEntry<any>} entry
25
+ * @returns {*} {boolean}
26
+ */
27
+ isExpired(entry) {
28
+ return Date.now() > entry.expiresAt;
29
+ }
30
+ /**
31
+ * 创建缓存条目
32
+ *
33
+ * @param {T} data
34
+ * @returns {*} {CacheEntry<T>}
35
+ */
36
+ createCacheEntry(data) {
37
+ return {
38
+ data,
39
+ expiresAt: Date.now() + this.CACHE_EXPIRATION_TIME
40
+ };
41
+ }
42
+ /**
43
+ * 加载模型信息,具有缓存和请求去重功能
44
+ *
45
+ * @author chitanda
46
+ * @date 2025-06-20 16:06:05
47
+ * @param {string} modelKey
48
+ * @returns {*} {Promise<ModelMetaDTO>}
49
+ */
50
+ async loadModel(modelKey) {
51
+ if (this.modelCache.has(modelKey)) {
52
+ const cacheEntry = this.modelCache.get(modelKey);
53
+ if (!this.isExpired(cacheEntry)) return cacheEntry.data;
54
+ this.modelCache.delete(modelKey);
55
+ }
56
+ if (this.modelLoadingCache.has(modelKey)) return this.modelLoadingCache.get(modelKey);
57
+ const loadPromise = (async () => {
58
+ try {
59
+ const data = await _api.apaas.modelMeta.getDetail({ modelKey });
60
+ if (data) {
61
+ this.modelCache.set(modelKey, this.createCacheEntry(data));
62
+ return data;
63
+ }
64
+ return {};
65
+ } finally {
66
+ this.modelLoadingCache.delete(modelKey);
67
+ }
68
+ })();
69
+ this.modelLoadingCache.set(modelKey, loadPromise);
70
+ return loadPromise;
71
+ }
72
+ /**
73
+ * 加载多个模型信息
74
+ *
75
+ * @author chitanda
76
+ * @date 2025-06-22 15:06:54
77
+ * @param {string[]} modelKeys
78
+ * @returns {*} {Promise<ModelMetaDTO[]>}
79
+ */
80
+ async loadModels(modelKeys) {
81
+ const cacheKey = modelKeys.join(",");
82
+ if (modelKeys.every((key) => {
83
+ const entry = this.modelCache.get(key);
84
+ return entry && !this.isExpired(entry);
85
+ })) return modelKeys.map((key) => this.modelCache.get(key).data);
86
+ modelKeys.forEach((key) => {
87
+ const entry = this.modelCache.get(key);
88
+ if (entry && this.isExpired(entry)) this.modelCache.delete(key);
89
+ });
90
+ if (this.modelsLoadingCache.has(cacheKey)) return this.modelsLoadingCache.get(cacheKey);
91
+ const loadPromise = (async () => {
92
+ try {
93
+ const pendingKeys = modelKeys.filter((key) => !this.modelCache.has(key));
94
+ if (pendingKeys.length > 0) {
95
+ const data = await _api.apaas.modelMeta.getByKeys({ modelKeys: pendingKeys.join(",") });
96
+ if (data && data.length > 0) data.forEach((model) => {
97
+ this.modelCache.set(model.key, this.createCacheEntry(model));
98
+ model.fieldMetaList = model.fieldMetas || [];
99
+ });
100
+ }
101
+ return modelKeys.map((key) => {
102
+ return this.modelCache.get(key).data;
103
+ });
104
+ } finally {
105
+ this.modelsLoadingCache.delete(cacheKey);
106
+ }
107
+ })();
108
+ this.modelsLoadingCache.set(cacheKey, loadPromise);
109
+ return loadPromise;
110
+ }
111
+ /**
112
+ * 加载指定模型的字段信息
113
+ *
114
+ * @author chitanda
115
+ * @date 2025-06-22 14:06:37
116
+ * @param {string} modelKey
117
+ * @param {string} fieldKey
118
+ * @returns {*} {(Promise<FieldMetaDTO | undefined>)}
119
+ */
120
+ async loadField(modelKey, fieldKey) {
121
+ const model = await this.loadModel(modelKey);
122
+ if (model?.fieldMetaList) return model.fieldMetaList.find((field) => field.key === fieldKey);
123
+ }
124
+ /**
125
+ * 加载指定模型的字段路径信息
126
+ *
127
+ * @author chitanda
128
+ * @date 2025-06-22 14:06:11
129
+ * @param {string} modelKey
130
+ * @param {string} fieldKey
131
+ * @returns {*} {Promise<string[]>}
132
+ */
133
+ async loadFieldPaths(modelKey, fieldKey, fieldCodeChain) {
134
+ if (!fieldCodeChain) return [];
135
+ const list = [];
136
+ const isFieldModel = !!fieldCodeChain.bindFieldKey;
137
+ const modelKeys = isFieldModel ? fieldCodeChain.modelLink || [fieldCodeChain.belongModelKey, fieldCodeChain.bindModelKey] : [fieldCodeChain.modelKey];
138
+ const models = await this.loadModels(modelKeys);
139
+ if (isFieldModel) list.push(...models.map((model) => model.name));
140
+ else {
141
+ const model = await this.loadModel(fieldCodeChain.modelKey);
142
+ if (model) list.push(model.name);
143
+ }
144
+ const model = await this.loadModel(modelKey);
145
+ if (model?.fieldMetaList) {
146
+ const field = model.fieldMetaList.find((field) => field.key === fieldKey);
147
+ if (field) list.push(field.name);
148
+ }
149
+ return list;
150
+ }
151
+ /**
152
+ * 加载指定模型的枚举列表
153
+ *
154
+ * @param {string} modelKey
155
+ * @param {string} fieldKey
156
+ * @param {string} [modelCategory=EntityModelCategoryEnum.ENTITY]
157
+ * @returns {*} {Promise<IObject[]>}
158
+ */
159
+ async loadEnumList(modelKey, fieldKey, modelCategory = EntityModelCategoryEnum.ENTITY) {
160
+ const cacheKey = `${modelCategory}:${modelKey}:${fieldKey}`;
161
+ if (this.enumCache.has(cacheKey)) {
162
+ const cacheEntry = this.enumCache.get(cacheKey);
163
+ if (!this.isExpired(cacheEntry)) return cloneDeep(cacheEntry.data);
164
+ this.enumCache.delete(cacheKey);
165
+ this.enumLoadingCache.delete(cacheKey);
166
+ }
167
+ if (this.enumLoadingCache.has(cacheKey)) return this.enumLoadingCache.get(cacheKey);
168
+ const loadPromise = (async () => {
169
+ try {
170
+ return [];
171
+ } finally {
172
+ this.enumLoadingCache.delete(cacheKey);
173
+ }
174
+ })();
175
+ this.enumLoadingCache.set(cacheKey, loadPromise);
176
+ return loadPromise;
177
+ }
178
+ /**
179
+ * 加载关联数据查询(QueryRef)
180
+ *
181
+ * @param {QueryRefDataRequest} request
182
+ * @returns {*} {Promise<ModelPageableRow>}
183
+ */
184
+ async loadQueryRefData(request) {
185
+ if (!request || !request.modelKey) throw new Error(`queryRefData 参数缺失`);
186
+ const cacheKey = JSON.stringify(request);
187
+ if (this.queryRefDataCache.has(cacheKey)) {
188
+ const cacheEntry = this.queryRefDataCache.get(cacheKey);
189
+ if (!this.isExpired(cacheEntry)) return cloneDeep(cacheEntry.data);
190
+ this.queryRefDataCache.delete(cacheKey);
191
+ this.queryRefDataLoadingCache.delete(cacheKey);
192
+ }
193
+ if (this.queryRefDataLoadingCache.has(cacheKey)) return this.queryRefDataLoadingCache.get(cacheKey);
194
+ const loadPromise = (async () => {
195
+ try {
196
+ const data = await _api.apaas.modelData.postQueryRefData(request);
197
+ if (data) {
198
+ this.queryRefDataCache.set(cacheKey, this.createCacheEntry(data));
199
+ return cloneDeep(data);
200
+ }
201
+ return {};
202
+ } finally {
203
+ this.queryRefDataLoadingCache.delete(cacheKey);
204
+ }
205
+ })();
206
+ this.queryRefDataLoadingCache.set(cacheKey, loadPromise);
207
+ return loadPromise;
208
+ }
209
+ /**
210
+ * 获取已缓存的模型
211
+ * @param modelKey 模型键
212
+ * @returns ModelMetaDTO | undefined
213
+ */
214
+ getCachedModel(modelKey) {
215
+ const entry = this.modelCache.get(modelKey);
216
+ if (entry && !this.isExpired(entry)) return entry.data;
217
+ if (entry && this.isExpired(entry)) this.modelCache.delete(modelKey);
218
+ }
219
+ /**
220
+ * 清除指定模型的缓存
221
+ *
222
+ * @author chitanda
223
+ * @date 2025-06-20 16:06:41
224
+ * @param {string} modelKey
225
+ */
226
+ clear(modelKey) {
227
+ this.modelCache.delete(modelKey);
228
+ this.modelLoadingCache.delete(modelKey);
229
+ const keysToDelete = [];
230
+ this.modelsLoadingCache.forEach((_, cacheKey) => {
231
+ if (cacheKey.includes(modelKey)) keysToDelete.push(cacheKey);
232
+ });
233
+ keysToDelete.forEach((key) => {
234
+ this.modelsLoadingCache.delete(key);
235
+ });
236
+ const enumKeysToDelete = [];
237
+ this.enumCache.forEach((_, cacheKey) => {
238
+ if (cacheKey.includes(modelKey)) enumKeysToDelete.push(cacheKey);
239
+ });
240
+ enumKeysToDelete.forEach((key) => {
241
+ this.enumCache.delete(key);
242
+ this.enumLoadingCache.delete(key);
243
+ });
244
+ const queryRefKeysToDelete = [];
245
+ this.queryRefDataCache.forEach((_, cacheKey) => {
246
+ if (cacheKey.includes(`"modelKey":"${modelKey}"`)) queryRefKeysToDelete.push(cacheKey);
247
+ });
248
+ queryRefKeysToDelete.forEach((key) => {
249
+ this.queryRefDataCache.delete(key);
250
+ this.queryRefDataLoadingCache.delete(key);
251
+ });
252
+ }
253
+ /**
254
+ * 清除所有模型缓存
255
+ *
256
+ * @author chitanda
257
+ * @date 2025-06-20 16:06:35
258
+ */
259
+ clearAll() {
260
+ this.modelCache.clear();
261
+ this.modelLoadingCache.clear();
262
+ this.modelsLoadingCache.clear();
263
+ this.enumCache.clear();
264
+ this.enumLoadingCache.clear();
265
+ this.queryRefDataCache.clear();
266
+ this.queryRefDataLoadingCache.clear();
267
+ }
268
+ /**
269
+ * 获取所有已缓存的模型键
270
+ *
271
+ * @author chitanda
272
+ * @date 2025-06-20 16:06:55
273
+ * @returns {*} {string[]}
274
+ */
275
+ keys() {
276
+ return Array.from(this.modelCache.keys());
277
+ }
278
+ };
279
+ var modelLoader = new ModelLoader();
280
+ //#endregion
326
281
  export { modelLoader };