@ibiz-template/model-helper 0.7.41-alpha.105 → 0.7.41-alpha.107
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/package.json +5 -4
- package/src/index.ts +7 -0
- package/src/locale/en/index.ts +16 -0
- package/src/locale/index.ts +2 -0
- package/src/locale/zh-CN/index.ts +14 -0
- package/src/model/PSSYSAPP.ts +12 -0
- package/src/model-helper.ts +804 -0
- package/src/model-loader.ts +95 -0
- package/src/model-util.ts +467 -0
- package/src/utils/format-path/format-path.ts +9 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/merge-model/merge-app-codelist.ts +42 -0
- package/src/utils/merge-model/merge-app-menu.ts +136 -0
- package/src/utils/merge-model/merge-app-uiaction-group.ts +85 -0
- package/src/utils/merge-model/merge-de-drcontrol.ts +175 -0
- package/src/utils/merge-model/merge-de-form.ts +326 -0
- package/src/utils/merge-model/merge-model-helper.ts +602 -0
- package/src/utils/merge-model/merge-model.ts +20 -0
- package/src/utils/merge-model/merge-treeview.ts +197 -0
- package/src/utils/plural/plural.ts +30 -0
- package/src/utils/service-path-util/service-path-util.ts +361 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { ModelLoaderProvider } from '@ibiz-template/runtime';
|
|
2
|
+
import {
|
|
3
|
+
IApplication,
|
|
4
|
+
IAppView,
|
|
5
|
+
IAppDataEntity,
|
|
6
|
+
IAppBIScheme,
|
|
7
|
+
IAppBICube,
|
|
8
|
+
IAppBIReport,
|
|
9
|
+
ISubAppRef,
|
|
10
|
+
IAppCodeList,
|
|
11
|
+
IAppLan,
|
|
12
|
+
} from '@ibiz/model-core';
|
|
13
|
+
import { ModelHelper } from './model-helper';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 模型加载适配器
|
|
17
|
+
*
|
|
18
|
+
* @author chitanda
|
|
19
|
+
* @date 2023-04-17 23:04:44
|
|
20
|
+
* @export
|
|
21
|
+
* @class ModelLoader
|
|
22
|
+
* @implements {ModelLoaderProvider}
|
|
23
|
+
*/
|
|
24
|
+
export class ModelLoader implements ModelLoaderProvider {
|
|
25
|
+
constructor(protected helper: ModelHelper) {}
|
|
26
|
+
|
|
27
|
+
initApp(id?: string): Promise<boolean> {
|
|
28
|
+
return this.helper.initApp(id);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
getApp(id?: string): Promise<IApplication> {
|
|
32
|
+
return this.helper.getAppModel(id);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
getSubAppRef(appId: string): Promise<ISubAppRef | undefined> {
|
|
36
|
+
return this.helper.getSubAppRef(appId);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
getAppView(appId: string, codeName: string): Promise<IAppView> {
|
|
40
|
+
return this.helper.getAppViewModel(codeName, appId);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
getAppDataEntity(appId: string, id: string): Promise<IAppDataEntity> {
|
|
44
|
+
return this.helper.getAppDataEntityModel(id, appId);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
getAppDataEntityByCodeName(
|
|
48
|
+
appId: string,
|
|
49
|
+
codeName: string,
|
|
50
|
+
): Promise<IAppDataEntity> {
|
|
51
|
+
return this.helper.getAppDataEntityModel(codeName, appId, false);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async getPSAppLang(
|
|
55
|
+
language: string,
|
|
56
|
+
appId?: string | IObject,
|
|
57
|
+
): Promise<IAppLan | null> {
|
|
58
|
+
return this.helper.getPSAppLang(language, appId);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
getAppStyle(appId: string): Promise<string | null> {
|
|
62
|
+
return this.helper.getAppStyle(appId);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
loadAppView(
|
|
66
|
+
appId: string,
|
|
67
|
+
viewId: string,
|
|
68
|
+
params: IParams,
|
|
69
|
+
): Promise<IAppView> {
|
|
70
|
+
return this.helper.loadAppViewModel(viewId, params, appId);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
getAppBISchemes(appId: string, ids: string[]): Promise<IAppBIScheme[]> {
|
|
74
|
+
return this.helper.getAppBISchemes(appId, ids);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
getAppAppBICubes(appId: string, ids: string[]): Promise<IAppBICube[]> {
|
|
78
|
+
return this.helper.getAppAppBICubes(appId, ids);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
getAppBIReports(appId: string, ids: string[]): Promise<IAppBIReport[]> {
|
|
82
|
+
return this.helper.getAppBIReports(appId, ids);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
translationModelToDsl(
|
|
86
|
+
data: IData,
|
|
87
|
+
type: 'APP' | 'VIEW' | 'CTRL' | 'APPENTITY' | 'APPBIREPORT',
|
|
88
|
+
): Promise<IModel | undefined> {
|
|
89
|
+
return this.helper.translationModelToDsl(data, type);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
mergeSubAppCodeList(codeList: IAppCodeList): void {
|
|
93
|
+
this.helper.mergeSubAppCodeList(codeList);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
import { calcUniqueTag } from '@ibiz/rt-model-api';
|
|
2
|
+
import { IAppDERS } from '@ibiz/model-core';
|
|
3
|
+
import { isEmpty } from 'ramda';
|
|
4
|
+
import { formatPath, mergeModel, ServicePathUtil } from './utils';
|
|
5
|
+
import { PSSysApp } from './model/PSSYSAPP';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 全动模型处理工具类,每个App一个实例
|
|
9
|
+
*
|
|
10
|
+
* @author chitanda
|
|
11
|
+
* @date 2023-04-16 17:04:06
|
|
12
|
+
* @export
|
|
13
|
+
* @class ModelUtil
|
|
14
|
+
*/
|
|
15
|
+
export class ModelUtil {
|
|
16
|
+
/**
|
|
17
|
+
* 模型缓存
|
|
18
|
+
*
|
|
19
|
+
* @author chitanda
|
|
20
|
+
* @date 2023-04-16 17:04:40
|
|
21
|
+
* @protected
|
|
22
|
+
* @type {Map<string, IModel>}
|
|
23
|
+
*/
|
|
24
|
+
protected modelCache: Map<string, IModel> = new Map();
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 应用模型
|
|
28
|
+
*
|
|
29
|
+
* @author chitanda
|
|
30
|
+
* @date 2023-04-16 17:04:17
|
|
31
|
+
* @protected
|
|
32
|
+
* @type {IModel}
|
|
33
|
+
*/
|
|
34
|
+
protected appModel!: IModel;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 服务路径计算工具类
|
|
38
|
+
*
|
|
39
|
+
* @author chitanda
|
|
40
|
+
* @date 2023-04-22 12:04:15
|
|
41
|
+
* @type {ServicePathUtil}
|
|
42
|
+
*/
|
|
43
|
+
servicePathUtil!: ServicePathUtil;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Creates an instance of GlobalModel.
|
|
47
|
+
*
|
|
48
|
+
* @author chitanda
|
|
49
|
+
* @date 2023-04-13 21:04:21
|
|
50
|
+
* @param {string}appId 应用标识
|
|
51
|
+
* @param {string} modelTag
|
|
52
|
+
* @param {(url: string, params?: IParams) => Promise<IModel>} get 模型加载方法
|
|
53
|
+
* @param {boolean} hub 是否为 hub 应用基座
|
|
54
|
+
* @param {IParams} appContext 应用级上下文参数
|
|
55
|
+
*/
|
|
56
|
+
constructor(
|
|
57
|
+
protected appId: string,
|
|
58
|
+
protected modelTag: string,
|
|
59
|
+
protected get: (url: string, params?: IParams) => Promise<IModel>,
|
|
60
|
+
protected hub: boolean,
|
|
61
|
+
protected appContext: IParams,
|
|
62
|
+
protected permission: boolean = true,
|
|
63
|
+
) {}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 在使用前需要初始化,来进行异步加载
|
|
67
|
+
*
|
|
68
|
+
* @author chitanda
|
|
69
|
+
* @date 2023-04-16 17:04:35
|
|
70
|
+
* @return {*} {Promise<void>}
|
|
71
|
+
*/
|
|
72
|
+
async init(): Promise<void> {
|
|
73
|
+
await this.getAppModel();
|
|
74
|
+
await this.specialHandling();
|
|
75
|
+
// 填充缓存模型
|
|
76
|
+
{
|
|
77
|
+
const { cache } = this.appModel;
|
|
78
|
+
if (cache) {
|
|
79
|
+
const views = cache.getPSAppViews;
|
|
80
|
+
if (views) {
|
|
81
|
+
views.forEach((item: IModel) => {
|
|
82
|
+
item.path = item.dynaModelFilePath;
|
|
83
|
+
const appPath = this.calcAppPath(item.path);
|
|
84
|
+
this.modelCache.set(appPath, item);
|
|
85
|
+
});
|
|
86
|
+
if (this.appModel.getAllPSAppViews == null) {
|
|
87
|
+
this.appModel.getAllPSAppViews = views;
|
|
88
|
+
} else {
|
|
89
|
+
this.appModel.getAllPSAppViews.push(...views);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const allDataEntities = (this.appModel.getAllPSAppDataEntities ||
|
|
95
|
+
[]) as IModel[];
|
|
96
|
+
allDataEntities.forEach(item => {
|
|
97
|
+
item.id = calcUniqueTag(item, false);
|
|
98
|
+
});
|
|
99
|
+
const allViews = (this.appModel.getAllPSAppViews || []) as IModel[];
|
|
100
|
+
allViews.forEach(item => {
|
|
101
|
+
item.id = calcUniqueTag(item, false);
|
|
102
|
+
});
|
|
103
|
+
const allAppDERSs = (this.appModel.getAllPSAppDERSs || []) as IModel[];
|
|
104
|
+
allAppDERSs.forEach(item => {
|
|
105
|
+
const major = item.getMajorPSAppDataEntity;
|
|
106
|
+
const minor = item.getMinorPSAppDataEntity;
|
|
107
|
+
item.majorAppDataEntityId = calcUniqueTag(major, false);
|
|
108
|
+
item.minorAppDataEntityId = calcUniqueTag(minor, false);
|
|
109
|
+
});
|
|
110
|
+
this.servicePathUtil = new ServicePathUtil(
|
|
111
|
+
allDataEntities,
|
|
112
|
+
allAppDERSs as IAppDERS[],
|
|
113
|
+
this,
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 特殊处理应用模型
|
|
119
|
+
*
|
|
120
|
+
* @author chitanda
|
|
121
|
+
* @date 2023-09-21 15:09:07
|
|
122
|
+
* @protected
|
|
123
|
+
* @return {*} {Promise<void>}
|
|
124
|
+
*/
|
|
125
|
+
protected async specialHandling(): Promise<void> {
|
|
126
|
+
// 特殊处理预置全局界面行为,附加一些特殊的模板预置模型
|
|
127
|
+
if (this.appModel.getAllPSAppDEUIActions) {
|
|
128
|
+
mergeModel(
|
|
129
|
+
this.appModel.getAllPSAppDEUIActions,
|
|
130
|
+
PSSysApp.getAllPSAppDEUIActions,
|
|
131
|
+
'codeName',
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* 获取应用模型
|
|
138
|
+
*
|
|
139
|
+
* @author chitanda
|
|
140
|
+
* @date 2023-04-16 17:04:21
|
|
141
|
+
* @return {*} {Promise<IModel>}
|
|
142
|
+
*/
|
|
143
|
+
async getAppModel(): Promise<IModel> {
|
|
144
|
+
if (!this.appModel) {
|
|
145
|
+
let appPath: string = '/PSSYSAPP.json';
|
|
146
|
+
if (this.hub && ibiz.env.hub) {
|
|
147
|
+
appPath = `/PSSYSAPP.hub.json`;
|
|
148
|
+
}
|
|
149
|
+
if (this.permission === false) {
|
|
150
|
+
appPath = `/simple/PSSYSAPP.simple.json`;
|
|
151
|
+
}
|
|
152
|
+
this.appModel = await this.getModel(appPath);
|
|
153
|
+
this.appModel.id = this.appId;
|
|
154
|
+
}
|
|
155
|
+
return this.appModel;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* 加载应用模型全局样式
|
|
160
|
+
*
|
|
161
|
+
* @author chitanda
|
|
162
|
+
* @date 2023-09-06 10:09:11
|
|
163
|
+
* @return {*} {(Promise<string | null>)}
|
|
164
|
+
*/
|
|
165
|
+
async getAppStyle(): Promise<string | null> {
|
|
166
|
+
let style: string = '';
|
|
167
|
+
try {
|
|
168
|
+
let stylePath: string = '/PSSYSAPP.json.css';
|
|
169
|
+
if (this.hub && ibiz.env.hub) {
|
|
170
|
+
stylePath = `/PSSYSAPP.hubsubapp.json.css`;
|
|
171
|
+
}
|
|
172
|
+
if (this.permission === false) {
|
|
173
|
+
stylePath = `/simple/PSSYSAPP.simple.json.css`;
|
|
174
|
+
}
|
|
175
|
+
style = await this.getStyleModel(stylePath);
|
|
176
|
+
if (style) {
|
|
177
|
+
return style;
|
|
178
|
+
}
|
|
179
|
+
} catch (error) {
|
|
180
|
+
// 忽略样式加载异常
|
|
181
|
+
ibiz.log.error(error);
|
|
182
|
+
}
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* 根据应用实体 codeName 或者 id 获取应用实体模型
|
|
188
|
+
*
|
|
189
|
+
* @author chitanda
|
|
190
|
+
* @date 2023-04-16 18:04:45
|
|
191
|
+
* @param {string} tag
|
|
192
|
+
* @param {boolean} [isId=true]
|
|
193
|
+
* @param {boolean} [ignoreCase=false]
|
|
194
|
+
* @return {*} {Promise<IModel>}
|
|
195
|
+
*/
|
|
196
|
+
async getAppDataEntityModel(
|
|
197
|
+
tag: string,
|
|
198
|
+
isId: boolean = true,
|
|
199
|
+
ignoreCase: boolean = false,
|
|
200
|
+
): Promise<IModel> {
|
|
201
|
+
const allDataEntities = this.appModel.getAllPSAppDataEntities as IModel[];
|
|
202
|
+
if (allDataEntities && allDataEntities.length > 0) {
|
|
203
|
+
const lowerTag = tag.toLowerCase();
|
|
204
|
+
let dataEntity: IModel | undefined;
|
|
205
|
+
if (isId) {
|
|
206
|
+
dataEntity = allDataEntities.find(v => {
|
|
207
|
+
if (ignoreCase) {
|
|
208
|
+
return v.id.toLowerCase() === lowerTag;
|
|
209
|
+
}
|
|
210
|
+
return v.id === tag;
|
|
211
|
+
});
|
|
212
|
+
} else {
|
|
213
|
+
dataEntity = allDataEntities.find(v => {
|
|
214
|
+
if (ignoreCase) {
|
|
215
|
+
return v.codeName.toLowerCase() === lowerTag;
|
|
216
|
+
}
|
|
217
|
+
return v.codeName === tag;
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
if (dataEntity) {
|
|
221
|
+
return this.getModel(dataEntity.path);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
throw new Error(
|
|
226
|
+
ibiz.i18n.t('modelHelper.noFoundEntity', { appId: this.appId, tag }),
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* 根据应用视图 id 获取应用视图模型,如果给了 params 则每次都会重新加载模型
|
|
232
|
+
*
|
|
233
|
+
* @author chitanda
|
|
234
|
+
* @date 2024-01-15 12:01:36
|
|
235
|
+
* @param {string} tag
|
|
236
|
+
* @param {IParams} [params]
|
|
237
|
+
* @param {boolean} [isDynamic]
|
|
238
|
+
* @return {*} {Promise<IModel>}
|
|
239
|
+
*/
|
|
240
|
+
async getAppViewModel(
|
|
241
|
+
tag: string,
|
|
242
|
+
params?: IParams,
|
|
243
|
+
isDynamic?: boolean,
|
|
244
|
+
): Promise<IModel> {
|
|
245
|
+
const allViews = this.appModel.getAllPSAppViews as IModel[];
|
|
246
|
+
if (allViews && allViews.length > 0) {
|
|
247
|
+
const lowerTag = tag.toLowerCase();
|
|
248
|
+
const exTag = `.${lowerTag}`;
|
|
249
|
+
const view = allViews.find(
|
|
250
|
+
v => v.id.endsWith(exTag) || v.id === lowerTag,
|
|
251
|
+
);
|
|
252
|
+
if (view) {
|
|
253
|
+
return this.getModel(view.path, params, isDynamic);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
throw new Error(
|
|
257
|
+
ibiz.i18n.t('modelHelper.noFoundView', { appId: this.appId, tag }),
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* 加载应用多语言模型
|
|
263
|
+
*
|
|
264
|
+
* @author chitanda
|
|
265
|
+
* @date 2023-08-24 22:08:23
|
|
266
|
+
* @param {string} language
|
|
267
|
+
* @return {*} {Promise<IModel>}
|
|
268
|
+
*/
|
|
269
|
+
async getPSAppLang(language: string): Promise<IModel> {
|
|
270
|
+
const app = await this.getAppModel();
|
|
271
|
+
if (app.getAllPSAppLans) {
|
|
272
|
+
const langs = app.getAllPSAppLans as IModel[];
|
|
273
|
+
const lang = langs.find(item => item.language === language);
|
|
274
|
+
if (lang) {
|
|
275
|
+
try {
|
|
276
|
+
const result = await this.getModel(
|
|
277
|
+
lang.path || lang.dynaModelFilePath,
|
|
278
|
+
);
|
|
279
|
+
return result;
|
|
280
|
+
} catch (error) {
|
|
281
|
+
ibiz.log.error(error);
|
|
282
|
+
return {};
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
ibiz.log.error(ibiz.i18n.t('modelHelper.noSupported', { language }));
|
|
286
|
+
}
|
|
287
|
+
return {};
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* 加载应用样式字符串
|
|
292
|
+
*
|
|
293
|
+
* @author chitanda
|
|
294
|
+
* @date 2023-09-07 11:09:11
|
|
295
|
+
* @param {string} modelPath
|
|
296
|
+
* @return {*} {Promise<string>}
|
|
297
|
+
*/
|
|
298
|
+
getStyleModel(modelPath: string): Promise<string> {
|
|
299
|
+
let url: string;
|
|
300
|
+
if (this.hub) {
|
|
301
|
+
url = this.calcAppPath(modelPath);
|
|
302
|
+
} else {
|
|
303
|
+
url = this.calcSubAppPath(modelPath);
|
|
304
|
+
}
|
|
305
|
+
return this.get(url) as unknown as Promise<string>;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* 获取应用智能报表体系集合
|
|
310
|
+
*
|
|
311
|
+
* @author tony001
|
|
312
|
+
* @date 2024-06-04 16:06:19
|
|
313
|
+
* @param {IModel[]} model
|
|
314
|
+
* @return {*} {Promise<IModel[]>}
|
|
315
|
+
*/
|
|
316
|
+
async getAppBISchemeModel(model: IModel[] = []): Promise<IModel[]> {
|
|
317
|
+
const appBISchemeModel: IModel[] = [];
|
|
318
|
+
if (model.length > 0) {
|
|
319
|
+
for (let i = 0; i < model.length; i++) {
|
|
320
|
+
const appBISchemeItem = await this.getModel(model[i].path);
|
|
321
|
+
appBISchemeModel.push(appBISchemeItem);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return appBISchemeModel;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* 获取应用智能报表立方体数据集合
|
|
329
|
+
*
|
|
330
|
+
* @author tony001
|
|
331
|
+
* @date 2024-06-04 16:06:19
|
|
332
|
+
* @param {IModel[]} [model=[]]
|
|
333
|
+
* @return {*} {Promise<IModel[]>}
|
|
334
|
+
*/
|
|
335
|
+
async getAppAppBICubes(model: IModel[] = []): Promise<IModel[]> {
|
|
336
|
+
const appBICubeModel: IModel[] = [];
|
|
337
|
+
if (model.length > 0) {
|
|
338
|
+
for (let i = 0; i < model.length; i++) {
|
|
339
|
+
const appBICubeItem = await this.getModel(model[i].path);
|
|
340
|
+
appBICubeModel.push(appBICubeItem);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return appBICubeModel;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* 获取应用智能报表数据集合
|
|
348
|
+
*
|
|
349
|
+
* @author tony001
|
|
350
|
+
* @date 2024-06-04 16:06:29
|
|
351
|
+
* @param {IModel[]} [model=[]]
|
|
352
|
+
* @return {*} {Promise<IModel[]>}
|
|
353
|
+
*/
|
|
354
|
+
async getAppBIReports(model: IModel[] = []): Promise<IModel[]> {
|
|
355
|
+
const appBIReportModel: IModel[] = [];
|
|
356
|
+
if (model.length > 0) {
|
|
357
|
+
for (let i = 0; i < model.length; i++) {
|
|
358
|
+
const appBIReportItem = await this.getModel(model[i].path);
|
|
359
|
+
appBIReportModel.push(appBIReportItem);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
return appBIReportModel;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* 加载模型,如果给了 params 则不会缓存模型
|
|
367
|
+
*
|
|
368
|
+
* @author chitanda
|
|
369
|
+
* @date 2024-01-15 12:01:57
|
|
370
|
+
* @param {string} modelPath
|
|
371
|
+
* @param {IParams} [params]
|
|
372
|
+
* @param {boolean} [isDynamic]
|
|
373
|
+
* @return {*} {Promise<IModel>}
|
|
374
|
+
*/
|
|
375
|
+
async getModel(
|
|
376
|
+
modelPath: string,
|
|
377
|
+
params?: IParams,
|
|
378
|
+
isDynamic?: boolean,
|
|
379
|
+
): Promise<IModel> {
|
|
380
|
+
let url: string;
|
|
381
|
+
if (this.hub) {
|
|
382
|
+
url = this.calcAppPath(modelPath, isDynamic);
|
|
383
|
+
} else {
|
|
384
|
+
url = this.calcSubAppPath(modelPath, isDynamic);
|
|
385
|
+
}
|
|
386
|
+
const isParams = params && !isEmpty(params);
|
|
387
|
+
if (this.modelCache.has(url) && !isParams) {
|
|
388
|
+
return this.modelCache.get(url)!;
|
|
389
|
+
}
|
|
390
|
+
const model = await this.get(url, params);
|
|
391
|
+
if (!isParams) {
|
|
392
|
+
this.modelCache.set(url, model);
|
|
393
|
+
}
|
|
394
|
+
this.deepFillAppId(model);
|
|
395
|
+
return model;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* 递归填充应用标识
|
|
400
|
+
*
|
|
401
|
+
* @author chitanda
|
|
402
|
+
* @date 2023-08-21 10:08:41
|
|
403
|
+
* @protected
|
|
404
|
+
* @param {IModel} model
|
|
405
|
+
*/
|
|
406
|
+
protected deepFillAppId(model: IModel): void {
|
|
407
|
+
model.appId = this.appId;
|
|
408
|
+
const keys = Object.keys(model);
|
|
409
|
+
keys.forEach(key => {
|
|
410
|
+
const value = model[key];
|
|
411
|
+
if (value && typeof value === 'object') {
|
|
412
|
+
if (Array.isArray(value)) {
|
|
413
|
+
value.forEach(item => {
|
|
414
|
+
if (item && typeof item === 'object') {
|
|
415
|
+
this.deepFillAppId(item);
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
} else {
|
|
419
|
+
this.deepFillAppId(value);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* 计算应用模型请求路径
|
|
427
|
+
*
|
|
428
|
+
* @author chitanda
|
|
429
|
+
* @date 2024-01-15 12:01:45
|
|
430
|
+
* @protected
|
|
431
|
+
* @param {string} modelPath
|
|
432
|
+
* @param {boolean} [isDynamic=false]
|
|
433
|
+
* @return {*} {string}
|
|
434
|
+
*/
|
|
435
|
+
protected calcAppPath(modelPath: string, isDynamic: boolean = false): string {
|
|
436
|
+
if (isDynamic) {
|
|
437
|
+
return formatPath(modelPath);
|
|
438
|
+
}
|
|
439
|
+
return `${formatPath(modelPath)}${
|
|
440
|
+
this.modelTag
|
|
441
|
+
? `?dynamodeltag=${this.modelTag}${this.appContext && this.appContext.srfembsubapp ? `&srfembsubapp=${this.appContext.srfembsubapp}` : ''}`
|
|
442
|
+
: ''
|
|
443
|
+
}`;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* 计算子应用模型请求路径
|
|
448
|
+
*
|
|
449
|
+
* @author chitanda
|
|
450
|
+
* @date 2024-01-15 12:01:39
|
|
451
|
+
* @protected
|
|
452
|
+
* @param {string} modelPath
|
|
453
|
+
* @param {boolean} [isDynamic=false]
|
|
454
|
+
* @return {*} {string}
|
|
455
|
+
*/
|
|
456
|
+
protected calcSubAppPath(
|
|
457
|
+
modelPath: string,
|
|
458
|
+
isDynamic: boolean = false,
|
|
459
|
+
): string {
|
|
460
|
+
if (isDynamic) {
|
|
461
|
+
return `/subapps/${this.appId}${formatPath(modelPath)}`;
|
|
462
|
+
}
|
|
463
|
+
return `/subapps/${this.appId}${formatPath(modelPath)}?dynamodeltag=${
|
|
464
|
+
this.modelTag
|
|
465
|
+
}`;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { formatPath } from './format-path/format-path';
|
|
2
|
+
export { mergeModel } from './merge-model/merge-model';
|
|
3
|
+
export { plural, pluralLower } from './plural/plural';
|
|
4
|
+
export {
|
|
5
|
+
ServicePathDeep,
|
|
6
|
+
ServicePathItem,
|
|
7
|
+
ServicePathUtil,
|
|
8
|
+
} from './service-path-util/service-path-util';
|
|
9
|
+
export { MergeSubModelHelper } from './merge-model/merge-model-helper';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { IAppCodeList } from '@ibiz/model-core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 合并应用代码表,子应用代码表需开启支持动态模式和配置用户标记,合并规则:dynamic_overlay:replace|merge,replace表示子应用代码表完全覆盖主应用代码表,merge表示子应用代码表项合并到主应用代码表项中(前提条件:主应用代码表和子应用代码表均是静态代码表),其他情况不做处理
|
|
5
|
+
* @param mainCodeList - 主应用代码表
|
|
6
|
+
* @param subCodeList - 子应用代码表
|
|
7
|
+
*/
|
|
8
|
+
export function mergeAppCodeList(
|
|
9
|
+
mainCodeList: IAppCodeList,
|
|
10
|
+
subCodeList: IAppCodeList,
|
|
11
|
+
): void {
|
|
12
|
+
const { userTag } = subCodeList as IModel;
|
|
13
|
+
if (!userTag) return;
|
|
14
|
+
const [mergeTag, mergeWay] = userTag.split(':');
|
|
15
|
+
if (
|
|
16
|
+
!mergeTag ||
|
|
17
|
+
!mergeWay ||
|
|
18
|
+
mergeTag !== 'dynamic_overlay' ||
|
|
19
|
+
(mergeWay !== 'replace' && mergeWay !== 'merge')
|
|
20
|
+
)
|
|
21
|
+
return;
|
|
22
|
+
switch (mergeWay) {
|
|
23
|
+
case 'replace':
|
|
24
|
+
mainCodeList = subCodeList;
|
|
25
|
+
break;
|
|
26
|
+
case 'merge':
|
|
27
|
+
if (
|
|
28
|
+
mainCodeList.codeListType === 'STATIC' &&
|
|
29
|
+
subCodeList.codeListType === 'STATIC'
|
|
30
|
+
) {
|
|
31
|
+
if (!mainCodeList.codeItems) mainCodeList.codeItems = [];
|
|
32
|
+
if (subCodeList.codeItems && subCodeList.codeItems.length > 0) {
|
|
33
|
+
subCodeList.codeItems.forEach(codeItem => {
|
|
34
|
+
mainCodeList.codeItems!.push(codeItem);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
break;
|
|
39
|
+
default:
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|