@ibiz-template/model-helper 0.7.41-alpha.11 → 0.7.41-alpha.111

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 (50) hide show
  1. package/dist/index.esm.js +1492 -3001
  2. package/dist/index.system.min.js +1 -1
  3. package/out/model-helper.d.ts +13 -1
  4. package/out/model-helper.d.ts.map +1 -1
  5. package/out/model-helper.js +47 -4
  6. package/out/model-loader.d.ts +3 -1
  7. package/out/model-loader.d.ts.map +1 -1
  8. package/out/model-loader.js +6 -0
  9. package/out/model-util.d.ts.map +1 -1
  10. package/out/model-util.js +8 -8
  11. package/out/utils/merge-model/merge-app-codelist.d.ts +8 -0
  12. package/out/utils/merge-model/merge-app-codelist.d.ts.map +1 -0
  13. package/out/utils/merge-model/merge-app-codelist.js +35 -0
  14. package/out/utils/merge-model/merge-app-menu.d.ts.map +1 -1
  15. package/out/utils/merge-model/merge-app-menu.js +8 -3
  16. package/out/utils/merge-model/merge-app-uiaction-group.d.ts +7 -0
  17. package/out/utils/merge-model/merge-app-uiaction-group.d.ts.map +1 -1
  18. package/out/utils/merge-model/merge-app-uiaction-group.js +54 -2
  19. package/out/utils/merge-model/merge-de-drcontrol.d.ts +8 -0
  20. package/out/utils/merge-model/merge-de-drcontrol.d.ts.map +1 -1
  21. package/out/utils/merge-model/merge-de-drcontrol.js +87 -4
  22. package/out/utils/merge-model/merge-de-form.d.ts +15 -0
  23. package/out/utils/merge-model/merge-de-form.d.ts.map +1 -1
  24. package/out/utils/merge-model/merge-de-form.js +56 -0
  25. package/out/utils/merge-model/merge-model-helper.d.ts +15 -1
  26. package/out/utils/merge-model/merge-model-helper.d.ts.map +1 -1
  27. package/out/utils/merge-model/merge-model-helper.js +101 -9
  28. package/out/utils/merge-model/merge-treeview.d.ts.map +1 -1
  29. package/out/utils/merge-model/merge-treeview.js +142 -6
  30. package/package.json +7 -6
  31. package/src/index.ts +7 -0
  32. package/src/locale/en/index.ts +16 -0
  33. package/src/locale/index.ts +2 -0
  34. package/src/locale/zh-CN/index.ts +14 -0
  35. package/src/model/PSSYSAPP.ts +12 -0
  36. package/src/model-helper.ts +804 -0
  37. package/src/model-loader.ts +95 -0
  38. package/src/model-util.ts +467 -0
  39. package/src/utils/format-path/format-path.ts +9 -0
  40. package/src/utils/index.ts +9 -0
  41. package/src/utils/merge-model/merge-app-codelist.ts +42 -0
  42. package/src/utils/merge-model/merge-app-menu.ts +136 -0
  43. package/src/utils/merge-model/merge-app-uiaction-group.ts +85 -0
  44. package/src/utils/merge-model/merge-de-drcontrol.ts +175 -0
  45. package/src/utils/merge-model/merge-de-form.ts +326 -0
  46. package/src/utils/merge-model/merge-model-helper.ts +602 -0
  47. package/src/utils/merge-model/merge-model.ts +20 -0
  48. package/src/utils/merge-model/merge-treeview.ts +197 -0
  49. package/src/utils/plural/plural.ts +30 -0
  50. package/src/utils/service-path-util/service-path-util.ts +361 -0
@@ -0,0 +1,804 @@
1
+ /* eslint-disable no-useless-return */
2
+ import {
3
+ IAppCodeList,
4
+ IAppDataEntity,
5
+ IAppView,
6
+ IApplication,
7
+ IAppLan,
8
+ ISubAppRef,
9
+ IAppBIScheme,
10
+ IAppBICube,
11
+ IAppBIReport,
12
+ } from '@ibiz/model-core';
13
+ import { DSLHelper, calcUniqueTag } from '@ibiz/rt-model-api';
14
+ import { ModelUtil } from './model-util';
15
+ import { ModelLoader } from './model-loader';
16
+ import { MergeSubModelHelper, plural } from './utils';
17
+
18
+ /**
19
+ * 模型加载工具类
20
+ *
21
+ * @author chitanda
22
+ * @date 2023-04-16 17:04:46
23
+ * @export
24
+ * @class ModelHelper
25
+ */
26
+ export class ModelHelper {
27
+ /**
28
+ * dsl解析包
29
+ *
30
+ * @author tony001
31
+ * @date 2024-09-26 16:09:49
32
+ * @protected
33
+ */
34
+ protected dsl = new DSLHelper();
35
+
36
+ /**
37
+ * 子应用模型合并对象
38
+ *
39
+ * @author tony001
40
+ * @date 2024-09-26 16:09:51
41
+ * @protected
42
+ */
43
+ protected merge = new MergeSubModelHelper();
44
+
45
+ /**
46
+ * 当前子应用清单
47
+ *
48
+ * @author chitanda
49
+ * @date 2023-12-06 15:12:30
50
+ * @protected
51
+ * @type {ISubAppRef[]}
52
+ */
53
+ protected subAppRefs: ISubAppRef[] = [];
54
+
55
+ /**
56
+ * 模型获取工具类缓存
57
+ *
58
+ * @author chitanda
59
+ * @date 2023-04-16 17:04:56
60
+ * @protected
61
+ * @type {Map<string, ModelUtil>}
62
+ */
63
+ protected cache: Map<string, ModelUtil> = new Map();
64
+
65
+ /**
66
+ * Creates an instance of ModelHelper.
67
+ * @author chitanda
68
+ * @date 2024-01-08 10:01:20
69
+ * @param {(url: string, params?: IParams) => Promise<IModel>} getModel 模型加载方法
70
+ * @param {string} defaultAppId 默认应用标识
71
+ * @param {string} appContext 应用级上下文参数
72
+ * @param {boolean} [permission=true] 是否启用权限
73
+ */
74
+ constructor(
75
+ protected getModel: (url: string, params?: IParams) => Promise<IModel>,
76
+ protected defaultAppId: string,
77
+ protected appContext: IParams,
78
+ protected permission: boolean = true,
79
+ ) {
80
+ ibiz.hub.registerModelLoaderProvider(new ModelLoader(this));
81
+ }
82
+
83
+ /**
84
+ * 初始化应用内容
85
+ *
86
+ * @author chitanda
87
+ * @date 2023-12-06 17:12:51
88
+ * @param {string} [id]
89
+ * @return {*} {Promise<boolean>}
90
+ */
91
+ async initApp(id?: string): Promise<boolean> {
92
+ await this.initToHub(id);
93
+ return true;
94
+ }
95
+
96
+ /**
97
+ * 初始化具体应用模型工具类
98
+ *
99
+ * @author chitanda
100
+ * @date 2023-04-16 17:04:41
101
+ * @param {string} modelTag
102
+ * @param {string} [appId=this.defaultAppId]
103
+ * @return {*} {Promise<void>}
104
+ */
105
+ async initModelUtil(
106
+ modelTag: string,
107
+ appId: string = this.defaultAppId,
108
+ ): Promise<void> {
109
+ const modelUtil = new ModelUtil(
110
+ appId,
111
+ modelTag,
112
+ this.getModel,
113
+ this.defaultAppId === appId,
114
+ this.appContext,
115
+ this.permission,
116
+ );
117
+ await modelUtil.init();
118
+ this.cache.set(appId, modelUtil);
119
+ }
120
+
121
+ /**
122
+ * 初始化模型至Hub中
123
+ *
124
+ * @author chitanda
125
+ * @date 2023-04-17 14:04:55
126
+ * @protected
127
+ * @param {(string | IObject)} [appId]
128
+ * @return {*} {Promise<void>}
129
+ */
130
+ protected async initToHub(appId?: string | IObject): Promise<void> {
131
+ const id: string = this.calcAppId(appId);
132
+ const app = ibiz.hub.getApp(id);
133
+ const modelUtil = this.getModelUtil(appId);
134
+ const appSourceModel = await modelUtil.getAppModel();
135
+ // 将引用的视图注册到 hub 清单中,只有主应用才会注册。子应用的注册由主应用在初始化子应用时搞定
136
+ if (appSourceModel.getAllPSAppViews && appId === ibiz.env.appId) {
137
+ const appViews = appSourceModel.getAllPSAppViews as IModel[];
138
+ appViews.forEach(appView => {
139
+ ibiz.hub.setAppView(appView.id, appSourceModel.id, appView.priority);
140
+ if (appView.defaultPage === true) {
141
+ ibiz.hub.defaultPage = appView;
142
+ }
143
+ });
144
+ }
145
+ // 将引用插件注册到 hub 清单中
146
+ if (appSourceModel.getAllPSAppPFPluginRefs && appId === ibiz.env.appId) {
147
+ const appPFPluginRefs =
148
+ appSourceModel.getAllPSAppPFPluginRefs as IModel[];
149
+ appPFPluginRefs.forEach(appPFPluginRef => {
150
+ ibiz.hub.setPlugin(this.dsl.appPFPluginRef(appPFPluginRef));
151
+ });
152
+ }
153
+ // 当前主应用的默认首页作为应用首页
154
+ if (appSourceModel.getDefaultPSAppIndexView && appId === ibiz.env.appId) {
155
+ const view = appSourceModel.getDefaultPSAppIndexView as IModel;
156
+ const name = view.path.split('/').pop().replace('.json', '');
157
+ ibiz.hub.defaultAppIndexViewName = name;
158
+ if (!ibiz.env.AppTitle) {
159
+ if (appSourceModel.caption) {
160
+ ibiz.env.AppTitle = appSourceModel.caption;
161
+ } else {
162
+ const views = appSourceModel.cache.getPSAppViews;
163
+ const indexView = views.find(
164
+ (viewItem: IModel) => viewItem.dynaModelFilePath === view.path,
165
+ );
166
+ if (indexView) {
167
+ ibiz.env.AppTitle = indexView.caption;
168
+ }
169
+ }
170
+ }
171
+ }
172
+ if (appSourceModel.getAllPSAppCodeLists) {
173
+ const codeLists = appSourceModel.getAllPSAppCodeLists as IAppCodeList[];
174
+ codeLists.forEach(codeList => {
175
+ app.codeList.setCodeList(
176
+ this.dsl.appCodeList(codeList) as IAppCodeList,
177
+ );
178
+ });
179
+ }
180
+ if (appSourceModel.getAllPSAppDataEntities) {
181
+ const dataEntities = appSourceModel.getAllPSAppDataEntities as IModel[];
182
+ dataEntities.forEach(dataEntity => {
183
+ app.deName2DeCodeName.set(dataEntity.name, dataEntity.codeName);
184
+ });
185
+ }
186
+ if (appSourceModel.getAllPSAppBISchemes) {
187
+ const allAppBISchemes = appSourceModel.getAllPSAppBISchemes as IModel[];
188
+ allAppBISchemes.forEach(biScheme => {
189
+ app.appBISchemeMap.set(calcUniqueTag(biScheme) as string, biScheme);
190
+ });
191
+ }
192
+ // 模型扩展标准视图布局面板
193
+ const subViewRefs = app.model.appSubViewTypeRefs || [];
194
+ subViewRefs.forEach((item: IModel) => {
195
+ if (item.replaceDefault) {
196
+ ibiz.util.layoutPanel.register(
197
+ `${item.viewType}_DEFAULT`,
198
+ item.viewLayoutPanel!,
199
+ );
200
+ }
201
+ });
202
+ // 子应用模型相关处理
203
+ {
204
+ const { subAppRefs = [] } = app.model;
205
+ const { getAllPSSubAppRefs = [] } = appSourceModel;
206
+ for (let i = 0; i < subAppRefs.length; i++) {
207
+ const subApp = subAppRefs[i];
208
+ const sourceSubApp = getAllPSSubAppRefs[i];
209
+ // 控制插件应用访问权限、通过应用样式参数SUBAPPACCESSKEY定义权限标识
210
+ if (subApp.accessKey) {
211
+ const mianApp = await ibiz.hub.getApp(ibiz.env.appId);
212
+ await mianApp.authority.init();
213
+ const permitted = mianApp.authority.calcByResCode(subApp.accessKey);
214
+ if (permitted) {
215
+ await this.initSubApp(app, subApp, sourceSubApp);
216
+ }
217
+ } else {
218
+ await this.initSubApp(app, subApp, sourceSubApp);
219
+ }
220
+ }
221
+ }
222
+ }
223
+
224
+ /**
225
+ * 递归填充指定应用标识
226
+ *
227
+ * @author tony001
228
+ * @date 2024-09-09 15:09:20
229
+ * @protected
230
+ * @param {IModel} model
231
+ * @param {string} appId
232
+ */
233
+ protected deepFillSubAppId(model: IModel, appId: string): void {
234
+ model.appId = appId;
235
+ const keys = Object.keys(model);
236
+ keys.forEach(key => {
237
+ const value = model[key];
238
+ if (value && typeof value === 'object') {
239
+ if (Array.isArray(value)) {
240
+ value.forEach(item => {
241
+ if (item && typeof item === 'object') {
242
+ this.deepFillSubAppId(item, appId);
243
+ }
244
+ });
245
+ } else {
246
+ this.deepFillSubAppId(value, appId);
247
+ }
248
+ }
249
+ });
250
+ }
251
+
252
+ /**
253
+ * 初始化子应用相关内容
254
+ *
255
+ * @author chitanda
256
+ * @date 2023-12-06 15:12:23
257
+ * @protected
258
+ * @param {IApplication} app
259
+ * @param {ISubAppRef} subApp
260
+ * @return {*} {Promise<void>}
261
+ */
262
+ protected async initSubApp(
263
+ app: IApplication,
264
+ subApp: ISubAppRef,
265
+ sourceSubApp: IModel,
266
+ ): Promise<void> {
267
+ this.subAppRefs.push(subApp);
268
+ // 设置视图到hub中
269
+ const viewIds = subApp.appViewIds || [];
270
+ const views = sourceSubApp.getAllPSAppViews || [];
271
+ viewIds.forEach((id, index) => {
272
+ const view = views[index];
273
+ ibiz.hub.setAppView(id, subApp.id, view.priority);
274
+ });
275
+ // 子应用插件引用注册到hub中
276
+ const appPFPluginRefs = sourceSubApp.getAllPSAppPFPluginRefs || [];
277
+ appPFPluginRefs.forEach((appPFPluginRef: IModel) => {
278
+ const appPluginRef = this.dsl.appPFPluginRef(appPFPluginRef);
279
+ appPluginRef.appId = subApp.id;
280
+ ibiz.hub.setPlugin(appPluginRef, subApp.id);
281
+ });
282
+ // 设置DrCtrl到hub中
283
+ const drCtrlIds = subApp.dedrcontrolIds || [];
284
+ const drCtrls = this.dsl.controls(sourceSubApp.getAllPSDEDRControls || []);
285
+ drCtrlIds.forEach((id, index) => {
286
+ const drCtrl = drCtrls[index];
287
+ if (drCtrl.controlType === 'TABEXPPANEL') {
288
+ ibiz.hub.registerSubAppTabExpPanel(subApp.id || ibiz.env.appId, drCtrl);
289
+ } else {
290
+ ibiz.hub.registerSubAppDrControls(subApp.id || ibiz.env.appId, drCtrl);
291
+ }
292
+ });
293
+ // 设置界面行为组到hub中
294
+ const appDEUIActionGroupIds = subApp.appDEUIActionGroupIds || [];
295
+ const appDEUIActionGroups = sourceSubApp.getAllPSAppDEUIActionGroups || [];
296
+ appDEUIActionGroupIds.forEach((id, index) => {
297
+ const appDEUIActionGroup = appDEUIActionGroups[index];
298
+ this.deepFillSubAppId(appDEUIActionGroup, subApp.id as string);
299
+ ibiz.hub.registerSubAppDEUIActionGroups(
300
+ subApp.id || ibiz.env.appId,
301
+ this.dsl.uiActionGroups(appDEUIActionGroup),
302
+ );
303
+ });
304
+ // 设置菜单模型到hub中
305
+ const appMenuModelIds = subApp.appMenuModelIds || [];
306
+ const appMenuModels = sourceSubApp.getAllPSAppMenuModels || [];
307
+ appMenuModelIds.forEach((id, index) => {
308
+ const appMenuModel = appMenuModels[index];
309
+ this.deepFillSubAppId(appMenuModel, subApp.id as string);
310
+ ibiz.hub.registerSubAppMenuModels(
311
+ subApp.id || ibiz.env.appId,
312
+ this.dsl.control(appMenuModel),
313
+ );
314
+ });
315
+ // 设置部件模型到hub中
316
+ const controlIds = subApp.controlIds || [];
317
+ const appControls = sourceSubApp.getAllPSControls || [];
318
+ controlIds.forEach((id, index) => {
319
+ const appControl = appControls[index];
320
+ this.deepFillSubAppId(appControl, subApp.id as string);
321
+ ibiz.hub.registerSubAppControls(
322
+ subApp.id || ibiz.env.appId,
323
+ this.dsl.control(appControl),
324
+ );
325
+ });
326
+ // 设置代码表模型到hub中
327
+ const appCodeLists = sourceSubApp.getAllPSAppCodeLists || [];
328
+ if (subApp.id) {
329
+ appCodeLists.forEach((appCodeList: IModel) => {
330
+ this.deepFillSubAppId(appCodeList, subApp.id as string);
331
+ ibiz.hub.registerSubAppCodeList(
332
+ subApp.id!,
333
+ this.dsl.appCodeList(appCodeList) as IAppCodeList,
334
+ );
335
+ });
336
+ }
337
+ // 实现子应用借助主应用独立打开,srfembsubapp的值为ref三段式的第一段哈希值,条件触发手动加载目标子应用
338
+ if (
339
+ this.appContext.srfembsubapp &&
340
+ subApp.id &&
341
+ subApp.id.startsWith(this.appContext.srfembsubapp)
342
+ ) {
343
+ await ibiz.hub.createApp(subApp.id);
344
+ }
345
+ }
346
+
347
+ /**
348
+ * 获取应用模型
349
+ *
350
+ * @author chitanda
351
+ * @date 2023-04-16 17:04:13
352
+ * @param {(string | IObject)} [appId]
353
+ * @return {*} {Promise<IApplication>}
354
+ */
355
+ async getAppModel(appId?: string | IObject): Promise<IApplication> {
356
+ const id: string = this.calcAppId(appId);
357
+ if (!this.cache.has(id)) {
358
+ const data = ibiz.appData || {};
359
+ await this.initModelUtil(data.dynamodeltag, id);
360
+ }
361
+ const model = await this.getModelUtil(appId).getAppModel();
362
+ const app = this.dsl.application(model) as IApplication;
363
+ // 设置应用原始模型到hub中
364
+ ibiz.hub.setAppSourceModel(app.appId, model);
365
+ // 实现子应用借助主应用独立打开,条件触发修改hub默认首页为子应用首页
366
+ if (
367
+ this.appContext.srfembsubapp &&
368
+ appId &&
369
+ appId.startsWith(this.appContext.srfembsubapp)
370
+ ) {
371
+ if (model.getDefaultPSAppIndexView) {
372
+ const view = model.getDefaultPSAppIndexView as IModel;
373
+ const name = view.path.split('/').pop().replace('.json', '');
374
+ ibiz.hub.defaultAppIndexViewName = name;
375
+ if (!ibiz.env.AppTitle) {
376
+ if (model.caption) {
377
+ ibiz.env.AppTitle = model.caption;
378
+ } else {
379
+ const views = model.cache.getPSAppViews;
380
+ const indexView = views.find(
381
+ (viewItem: IModel) => viewItem.dynaModelFilePath === view.path,
382
+ );
383
+ if (indexView) {
384
+ ibiz.env.AppTitle = indexView.caption;
385
+ }
386
+ }
387
+ }
388
+ }
389
+ }
390
+ return app;
391
+ }
392
+
393
+ /**
394
+ * 获取子应用引用模型
395
+ *
396
+ * @author tony001
397
+ * @date 2024-06-23 15:06:31
398
+ * @param {string} appId
399
+ * @return {*} {(Promise<ISubAppRef | undefined>)}
400
+ */
401
+ async getSubAppRef(appId: string): Promise<ISubAppRef | undefined> {
402
+ return this.subAppRefs.find(subApp => {
403
+ return subApp.appId === appId;
404
+ });
405
+ }
406
+
407
+ /**
408
+ * 获取应用全局样式
409
+ *
410
+ * @author chitanda
411
+ * @date 2023-09-06 10:09:48
412
+ * @param {(string | IObject)} [appId]
413
+ * @return {*} {(Promise<string | null>)}
414
+ */
415
+ getAppStyle(appId?: string | IObject): Promise<string | null> {
416
+ return this.getModelUtil(appId).getAppStyle();
417
+ }
418
+
419
+ /**
420
+ * @description 计算应用实体需要合并的子应用模型
421
+ * @protected
422
+ * @param {IAppDataEntity} appDataEntity
423
+ * @memberof ModelHelper
424
+ */
425
+ protected calcAppDataEntitySubAppModel(appDataEntity: IAppDataEntity): void {
426
+ // 合并AC模式界面行为组
427
+ this.merge.mergeSubAppDEACModesActionGroup(
428
+ appDataEntity.appDEACModes,
429
+ this.subAppRefs,
430
+ );
431
+ }
432
+
433
+ /**
434
+ * 根据应用实体 codeName 获取应用实体模型
435
+ *
436
+ * @author chitanda
437
+ * @date 2023-04-16 18:04:33
438
+ * @param {string} name
439
+ * @param {(string | IObject)} [appId]
440
+ * @param {boolean} [isId]
441
+ * @return {*} {Promise<IAppDataEntity>}
442
+ */
443
+ async getAppDataEntityModel(
444
+ name: string,
445
+ appId?: string | IObject,
446
+ isId?: boolean,
447
+ ): Promise<IAppDataEntity> {
448
+ const util = this.getModelUtil(appId);
449
+ const model = await util.getAppDataEntityModel(name, isId, true);
450
+ const dsl = this.dsl.appDataEntity(model) as IAppDataEntity;
451
+ if (!appId || appId === ibiz.env.appId) {
452
+ this.calcAppDataEntitySubAppModel(dsl);
453
+ }
454
+ const list = await util.servicePathUtil.calcRequestPaths(dsl.id!);
455
+ dsl.requestPaths = list;
456
+ dsl.codeName2 = plural(dsl.codeName!.toLowerCase());
457
+ dsl.defullTag = calcUniqueTag(
458
+ model.getPSDataEntity,
459
+ false,
460
+ false,
461
+ ) as string;
462
+ if (dsl.deapicodeName) {
463
+ if (!dsl.deapicodeName2) {
464
+ dsl.deapicodeName2 = plural(dsl.deapicodeName);
465
+ }
466
+ const { engineVer } = (await util.getAppModel()) as IApplication;
467
+ if (!engineVer || engineVer < 240) {
468
+ dsl.deapicodeName2 = dsl.deapicodeName2!.toLowerCase();
469
+ }
470
+ }
471
+
472
+ return dsl;
473
+ }
474
+
475
+ /**
476
+ * 计算应用视图需要合并的子应用模型
477
+ *
478
+ * @author chitanda
479
+ * @date 2023-12-06 16:12:25
480
+ * @protected
481
+ * @param {IAppView} view
482
+ */
483
+ protected calcAppViewSubAppModel(view: IAppView): void {
484
+ const controls = view.controls
485
+ ? view.controls
486
+ : view.viewLayoutPanel?.controls;
487
+
488
+ // 合并主菜单
489
+ this.merge.mergeAppMainMenu(view, controls, this.subAppRefs);
490
+ // 合并扩展菜单
491
+ this.merge.mergeSubAppExtendedMenu(view, controls, this.subAppRefs);
492
+ // 合并DrCtrl
493
+ this.merge.mergeSubAppDRCtrl(view, controls, this.subAppRefs);
494
+ // 合并工具栏界面行为组
495
+ this.merge.mergeSubAppToolbarActionGroup(view, controls, this.subAppRefs);
496
+ // 合并上下文菜单(树视图部件)
497
+ this.merge.mergeSubAppTreeContextMenuActionGroup(
498
+ view,
499
+ controls,
500
+ this.subAppRefs,
501
+ );
502
+ // 合并表单界面行为组(按钮组)
503
+ this.merge.mergeSubAppFormActionGroup(view, controls, this.subAppRefs);
504
+ // 合并表格列界面行为组
505
+ this.merge.mergeSubAppGridCloumnActionGroup(
506
+ view,
507
+ controls,
508
+ this.subAppRefs,
509
+ );
510
+ // 合并树视图部件
511
+ this.merge.mergeSubAppTreeView(view, controls, this.subAppRefs);
512
+ // 合并子应用表单部件
513
+ this.merge.mergeSubAppForm(view, controls, this.subAppRefs);
514
+ }
515
+
516
+ /**
517
+ * 根据应用视图 codeName 获取应用视图模型
518
+ *
519
+ * @author chitanda
520
+ * @date 2023-04-16 17:04:38
521
+ * @param {string} name
522
+ * @param {(string | IObject)} [appId]
523
+ * @return {*} {Promise<IAppView>}
524
+ */
525
+ async getAppViewModel(
526
+ name: string,
527
+ appId?: string | IObject,
528
+ ): Promise<IAppView> {
529
+ const model = await this.getModelUtil(appId).getAppViewModel(name);
530
+ const dsl = this.dsl.appView(model) as IAppView;
531
+ this.calcAppViewSubAppModel(dsl);
532
+ return dsl;
533
+ }
534
+
535
+ /**
536
+ * 根据路径和参数加载应用视图模型,主要用于后台根据运行时参数重新计算视图模型
537
+ *
538
+ * @author chitanda
539
+ * @date 2024-01-08 10:01:43
540
+ * @param {string} viewId
541
+ * @param {IParams} [params]
542
+ * @param {string} [appId]
543
+ * @return {*} {Promise<IAppView>}
544
+ */
545
+ async loadAppViewModel(
546
+ viewId: string,
547
+ params?: IParams,
548
+ appId?: string,
549
+ ): Promise<IAppView> {
550
+ const model = await this.getModelUtil(appId).getAppViewModel(
551
+ viewId,
552
+ params,
553
+ true,
554
+ );
555
+ const dsl = this.dsl.appView(model) as IAppView;
556
+ this.calcAppViewSubAppModel(dsl);
557
+ return dsl;
558
+ }
559
+
560
+ /**
561
+ * 获取应用多语言模型
562
+ *
563
+ * @author chitanda
564
+ * @date 2023-08-24 21:08:17
565
+ * @param {string} language
566
+ * @param {(string | IObject)} [appId]
567
+ * @return {*} {Promise<IAppLan>}
568
+ */
569
+ async getPSAppLang(
570
+ language: string,
571
+ appId?: string | IObject,
572
+ ): Promise<IAppLan> {
573
+ const model = await this.getModelUtil(appId).getPSAppLang(language);
574
+ return this.dsl.appLan(model) as IAppLan;
575
+ }
576
+
577
+ /**
578
+ * 获取应用智能报表体系集合
579
+ *
580
+ * @author tony001
581
+ * @date 2024-06-04 15:06:46
582
+ * @param {string} appId 应用标识
583
+ * @param {string[]} ids 智能报表体系标识集合
584
+ * @return {*} {Promise<IAppBIScheme[]>}
585
+ */
586
+ async getAppBISchemes(
587
+ appId: string,
588
+ ids: string[] = [],
589
+ ): Promise<IAppBIScheme[]> {
590
+ const tag: string = this.calcAppId(appId);
591
+ const app = ibiz.hub.getApp(tag);
592
+ const modelUtil = this.getModelUtil(appId);
593
+ const appBISchemes: IAppBIScheme[] = [];
594
+ if (ids.length === 0) {
595
+ ids = app.model.appBISchemeIds || [];
596
+ }
597
+ if (ids.length > 0) {
598
+ const sourceModel: IModel[] = ids.map(id => {
599
+ return app.appBISchemeMap.get(id) as IModel;
600
+ });
601
+ const models = await modelUtil.getAppBISchemeModel(sourceModel);
602
+ if (models && models.length > 0) {
603
+ for (let i = 0; i < models.length; i++) {
604
+ const model = models[i];
605
+ if (model.getPSAppBICubes?.length > 0) {
606
+ for (let m = 0; m < model.getPSAppBICubes.length; m++) {
607
+ app.appBICubeMap.set(
608
+ calcUniqueTag(model.getPSAppBICubes[m]) as string,
609
+ model.getPSAppBICubes[m],
610
+ );
611
+ }
612
+ }
613
+ if (model.getPSAppBIReports?.length > 0) {
614
+ for (let n = 0; n < model.getPSAppBIReports.length; n++) {
615
+ app.appBIReportMap.set(
616
+ calcUniqueTag(model.getPSAppBIReports[n]) as string,
617
+ model.getPSAppBIReports[n],
618
+ );
619
+ }
620
+ }
621
+ appBISchemes.push(this.dsl.appBIScheme(model) as IAppBIScheme);
622
+ }
623
+ }
624
+ }
625
+ return appBISchemes;
626
+ }
627
+
628
+ /**
629
+ * 获取应用智能报表立方体集合
630
+ *
631
+ * @author tony001
632
+ * @date 2024-06-04 16:06:19
633
+ * @param {string} appId 应用标识
634
+ * @param {string[]} [ids=[]] 立方体数据标识集合
635
+ * @return {*} {Promise<IAppBICube[]>}
636
+ */
637
+ async getAppAppBICubes(
638
+ appId: string,
639
+ ids: string[] = [],
640
+ ): Promise<IAppBICube[]> {
641
+ const tag: string = this.calcAppId(appId);
642
+ const app = ibiz.hub.getApp(tag);
643
+ const modelUtil = this.getModelUtil(appId);
644
+ const appBICubes: IAppBICube[] = [];
645
+ if (ids.length === 0) {
646
+ return appBICubes;
647
+ }
648
+ if (ids.length > 0) {
649
+ const sourceModel: IModel[] = [];
650
+ const noExistIds: string[] = [];
651
+ ids.forEach(id => {
652
+ const tempCube = app.appBICubeMap.get(id);
653
+ if (tempCube) {
654
+ sourceModel.push(tempCube);
655
+ } else {
656
+ noExistIds.push(id);
657
+ }
658
+ });
659
+ if (noExistIds.length > 0) {
660
+ await this.getAppBISchemes(appId);
661
+ noExistIds.forEach(id => {
662
+ const tempCube = app.appBICubeMap.get(id);
663
+ if (tempCube) {
664
+ sourceModel.push(tempCube);
665
+ }
666
+ });
667
+ }
668
+ const models = await modelUtil.getAppAppBICubes(sourceModel);
669
+ if (models && models.length > 0) {
670
+ for (let i = 0; i < models.length; i++) {
671
+ const model = models[i];
672
+ appBICubes.push(this.dsl.appBICube(model) as IAppBIScheme);
673
+ }
674
+ }
675
+ }
676
+ return appBICubes;
677
+ }
678
+
679
+ /**
680
+ * 获取应用智能报表集合
681
+ *
682
+ * @author tony001
683
+ * @date 2024-06-04 16:06:39
684
+ * @param {string} appId 应用标识
685
+ * @param {string[]} [ids=[]] 报表数据标识集合
686
+ * @return {*} {Promise<IAppBIReport[]>}
687
+ */
688
+ async getAppBIReports(
689
+ appId: string,
690
+ ids: string[] = [],
691
+ ): Promise<IAppBIReport[]> {
692
+ const tag: string = this.calcAppId(appId);
693
+ const app = ibiz.hub.getApp(tag);
694
+ const modelUtil = this.getModelUtil(appId);
695
+ const appBIReports: IAppBIReport[] = [];
696
+ if (ids.length === 0) {
697
+ return appBIReports;
698
+ }
699
+ if (ids.length > 0) {
700
+ const sourceModel: IModel[] = [];
701
+ const noExistIds: string[] = [];
702
+ ids.forEach(id => {
703
+ const tempReport = app.appBIReportMap.get(id);
704
+ if (tempReport) {
705
+ sourceModel.push(tempReport);
706
+ } else {
707
+ noExistIds.push(id);
708
+ }
709
+ });
710
+ if (noExistIds.length > 0) {
711
+ await this.getAppBISchemes(appId);
712
+ noExistIds.forEach(id => {
713
+ const tempReport = app.appBIReportMap.get(id);
714
+ if (tempReport) {
715
+ sourceModel.push(tempReport);
716
+ }
717
+ });
718
+ }
719
+ const models = await modelUtil.getAppBIReports(sourceModel);
720
+ if (models && models.length > 0) {
721
+ for (let i = 0; i < models.length; i++) {
722
+ const model = models[i];
723
+ appBIReports.push(this.dsl.appBIReport(model) as IAppBIScheme);
724
+ }
725
+ }
726
+ }
727
+ return appBIReports;
728
+ }
729
+
730
+ /**
731
+ * 原始模型转化为dsl对象
732
+ *
733
+ * @author tony001
734
+ * @date 2024-06-27 17:06:54
735
+ * @param {ModelObject} data
736
+ * @param {('APP' | 'VIEW' | 'CTRL' | 'APPENTITY' | 'APPBIREPORT')} type
737
+ * @return {*} {(Promise<IData | undefined>)}
738
+ */
739
+ async translationModelToDsl(
740
+ data: ModelObject,
741
+ type: 'APP' | 'VIEW' | 'CTRL' | 'APPENTITY' | 'APPBIREPORT',
742
+ ): Promise<IData | undefined> {
743
+ switch (type) {
744
+ case 'APP':
745
+ return this.dsl.application(data);
746
+ case 'VIEW':
747
+ return this.dsl.appView(data);
748
+ case 'CTRL':
749
+ return this.dsl.control(data);
750
+ case 'APPENTITY':
751
+ return this.dsl.appDataEntity(data);
752
+ case 'APPBIREPORT':
753
+ return this.dsl.appBIReport(data);
754
+ default:
755
+ break;
756
+ }
757
+ }
758
+
759
+ /**
760
+ * 获取对应模型工具类
761
+ *
762
+ * @author chitanda
763
+ * @date 2023-04-16 18:04:08
764
+ * @protected
765
+ * @param {(IObject | string)} context
766
+ * @return {*} {ModelUtil}
767
+ */
768
+ protected getModelUtil(
769
+ context: IObject | string = this.defaultAppId,
770
+ ): ModelUtil {
771
+ const appId: string = this.calcAppId(context);
772
+ if (this.cache.has(appId)) {
773
+ return this.cache.get(appId)!;
774
+ }
775
+ throw new Error(ibiz.i18n.t('modelHelper.noInitialized', { appId }));
776
+ }
777
+
778
+ /**
779
+ * 计算应用标识
780
+ *
781
+ * @author chitanda
782
+ * @date 2023-04-16 17:04:19
783
+ * @protected
784
+ * @param {(IObject | string)} [data=this.defaultAppId]
785
+ * @return {*} {string}
786
+ */
787
+ protected calcAppId(data: IObject | string = this.defaultAppId): string {
788
+ let appId: string;
789
+ if (typeof data === 'string') {
790
+ appId = data;
791
+ } else {
792
+ appId = (data as { appId: string }).appId;
793
+ }
794
+ return appId;
795
+ }
796
+
797
+ /**
798
+ * 合并子应用代码表
799
+ * @param codeList
800
+ */
801
+ mergeSubAppCodeList(codeList: IAppCodeList): void {
802
+ this.merge.mergeSubAppCodeList(codeList, this.subAppRefs);
803
+ }
804
+ }