@ibiz-template/model-helper 0.7.41-alpha.3 → 0.7.41-alpha.30

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.
@@ -5,6 +5,7 @@ import { mergeAppMenu } from './merge-app-menu';
5
5
  import { mergeDEDrControl } from './merge-de-drcontrol';
6
6
  import { mergeAppDEUIActionGroup } from './merge-app-uiaction-group';
7
7
  import { mergeTreeView } from './merge-treeview';
8
+ import { getFormdataRelationTags, mergeAppDEForm, mergeFormDRTabpanel, } from './merge-de-form';
8
9
  /**
9
10
  * 子应用模型合并对象
10
11
  *
@@ -33,6 +34,11 @@ export class MergeSubModelHelper {
33
34
  * @param {ISubAppRef[]} subAppRefs
34
35
  */
35
36
  mergeAppMainMenu(view, controls, subAppRefs) {
37
+ // config.common.mergeAppMenu参数值为disable,不处理该应用的菜单合并
38
+ if (ibiz.config.common.mergeAppMenu &&
39
+ ibiz.config.common.mergeAppMenu === 'disable') {
40
+ return;
41
+ }
36
42
  const dstAppMenu = controls === null || controls === void 0 ? void 0 : controls.find(item => {
37
43
  return item.controlType === 'APPMENU' && item.name === 'appmenu';
38
44
  });
@@ -40,6 +46,23 @@ export class MergeSubModelHelper {
40
46
  for (let i = 0; i < subAppRefs.length; i++) {
41
47
  const srcAppMenu = subAppRefs[i].appMenuModel;
42
48
  if (srcAppMenu) {
49
+ const { userTag } = srcAppMenu;
50
+ if (userTag) {
51
+ const [userKey, userValue] = userTag.split(':');
52
+ // mergemenutag: 目标菜单代码名称,目标菜单代码名称建议识别正则缺省配置以匹配更多目标
53
+ if (userKey === 'mergemenutag') {
54
+ try {
55
+ const userValueReg = new RegExp(userValue);
56
+ if (!userValueReg.test(dstAppMenu.codeName)) {
57
+ continue;
58
+ }
59
+ }
60
+ catch (error) {
61
+ ibiz.log.warn(`[菜单合并]:无效的正则表达式${userValue},忽略处理`);
62
+ continue;
63
+ }
64
+ }
65
+ }
43
66
  mergeAppMenu(dstAppMenu, srcAppMenu);
44
67
  }
45
68
  }
@@ -55,6 +78,11 @@ export class MergeSubModelHelper {
55
78
  * @return {*} {void}
56
79
  */
57
80
  mergeSubAppExtendedMenu(view, controls, subAppRefs) {
81
+ // config.common.mergeAppMenu参数值为disable,不处理该应用的菜单合并
82
+ if (ibiz.config.common.mergeAppMenu &&
83
+ ibiz.config.common.mergeAppMenu === 'disable') {
84
+ return;
85
+ }
58
86
  if (view.viewType !== 'APPINDEXVIEW' || !controls)
59
87
  return;
60
88
  const dstAppMenus = controls.filter(item => {
@@ -113,27 +141,7 @@ export class MergeSubModelHelper {
113
141
  });
114
142
  if (dstToolBar && dstToolBar.detoolbarItems) {
115
143
  const dstToolBarItems = dstToolBar.detoolbarItems;
116
- if (dstToolBarItems && dstToolBarItems.length > 0) {
117
- for (let i = 0; i < dstToolBarItems.length; i++) {
118
- const dstToolBarItem = dstToolBarItems[i];
119
- if (dstToolBarItem &&
120
- dstToolBarItem.uiactionGroup) {
121
- const dstUIActionGroup = dstToolBarItem
122
- .uiactionGroup;
123
- if (dstUIActionGroup) {
124
- for (let j = 0; j < subAppRefs.length; j++) {
125
- if (subAppRefs[j].appId === view.appId) {
126
- continue;
127
- }
128
- const srcAppDEUIActionGroup = ibiz.hub.getSubAppDEUIActionGroups(dstUIActionGroup.uniqueTag, subAppRefs[j].appId);
129
- if (srcAppDEUIActionGroup) {
130
- mergeAppDEUIActionGroup(dstToolBarItems[i].uiactionGroup, srcAppDEUIActionGroup);
131
- }
132
- }
133
- }
134
- }
135
- }
136
- }
144
+ this.recursiveMergeSubAppToolbarItemActionGroup(dstToolBarItems, view, subAppRefs);
137
145
  }
138
146
  controls.forEach(control => {
139
147
  if (control && control.controls) {
@@ -141,6 +149,40 @@ export class MergeSubModelHelper {
141
149
  }
142
150
  });
143
151
  }
152
+ /**
153
+ * @description 递归合并工具项界面行为组
154
+ * @param {IDEToolbarItem[]} dstToolBarItems
155
+ * @param {IAppView} view
156
+ * @param {ISubAppRef[]} subAppRefs
157
+ * @memberof MergeSubModelHelper
158
+ */
159
+ recursiveMergeSubAppToolbarItemActionGroup(dstToolBarItems, view, subAppRefs) {
160
+ if (dstToolBarItems && dstToolBarItems.length > 0) {
161
+ for (let i = 0; i < dstToolBarItems.length; i++) {
162
+ const dstToolBarItem = dstToolBarItems[i];
163
+ if (dstToolBarItem &&
164
+ dstToolBarItem.uiactionGroup) {
165
+ const dstUIActionGroup = dstToolBarItem
166
+ .uiactionGroup;
167
+ if (dstUIActionGroup) {
168
+ for (let j = 0; j < subAppRefs.length; j++) {
169
+ if (subAppRefs[j].appId === view.appId) {
170
+ continue;
171
+ }
172
+ const srcAppDEUIActionGroup = ibiz.hub.getSubAppDEUIActionGroups(dstUIActionGroup.uniqueTag, subAppRefs[j].appId);
173
+ if (srcAppDEUIActionGroup) {
174
+ mergeAppDEUIActionGroup(dstToolBarItems[i].uiactionGroup, srcAppDEUIActionGroup);
175
+ }
176
+ }
177
+ }
178
+ }
179
+ if (dstToolBarItem.detoolbarItems) {
180
+ this.recursiveMergeSubAppToolbarItemActionGroup(dstToolBarItem
181
+ .detoolbarItems, view, subAppRefs);
182
+ }
183
+ }
184
+ }
185
+ }
144
186
  /**
145
187
  * 合并树上下文菜单
146
188
  *
@@ -179,13 +221,15 @@ export class MergeSubModelHelper {
179
221
  if (srcAppDEUIActionGroup) {
180
222
  mergeAppDEUIActionGroup(dstContextMenuItems[i]
181
223
  .uiactionGroup, srcAppDEUIActionGroup);
182
- const targetDeTreeNode = (_b = dstTree.detreeNodes) === null || _b === void 0 ? void 0 : _b.find(treeNode => {
224
+ const targetDeTreeNodes = (_b = dstTree.detreeNodes) === null || _b === void 0 ? void 0 : _b.filter(treeNode => {
183
225
  return (treeNode.decontextMenu &&
184
226
  treeNode.decontextMenu.modelId ===
185
227
  dstContextMenu.modelId);
186
228
  });
187
- if (targetDeTreeNode) {
188
- targetDeTreeNode.decontextMenu = dstContextMenu;
229
+ if (targetDeTreeNodes && targetDeTreeNodes.length > 0) {
230
+ targetDeTreeNodes.forEach(targetDeTreeNode => {
231
+ targetDeTreeNode.decontextMenu = dstContextMenu;
232
+ });
189
233
  }
190
234
  }
191
235
  }
@@ -297,4 +341,42 @@ export class MergeSubModelHelper {
297
341
  });
298
342
  }
299
343
  }
344
+ /**
345
+ * @description 合并子应用表单(实体代码标识和表单代码标识一致)
346
+ * @param {IAppView} view
347
+ * @param {(IControl[] | undefined)} controls
348
+ * @param {ISubAppRef[]} subAppRefs
349
+ * @memberof MergeSubModelHelper
350
+ */
351
+ mergeSubAppForm(view, controls, subAppRefs) {
352
+ if (!controls)
353
+ return;
354
+ const forms = controls.filter(item => {
355
+ return item.controlType === 'FORM';
356
+ });
357
+ if (forms.length === 0)
358
+ return;
359
+ forms.forEach(dstForm => {
360
+ const ids = dstForm.id.split('.');
361
+ // 查找源表单存在基于数据关系部件构建的分页部件的数据关系标识
362
+ const dataRelationTags = getFormdataRelationTags(dstForm);
363
+ for (let i = 0; i < subAppRefs.length; i++) {
364
+ const srcForm = ibiz.hub.getSubAppControl(ids[1] + ids[2], subAppRefs[i].appId);
365
+ // 常规表单合并
366
+ if (srcForm) {
367
+ mergeAppDEForm(dstForm, srcForm);
368
+ }
369
+ // 表单分页部件合并(数据关系部件)
370
+ if (dataRelationTags && dataRelationTags.length > 0) {
371
+ for (let j = 0; j < dataRelationTags.length; j++) {
372
+ const dataRelationTag = dataRelationTags[j];
373
+ const dataRelationForm = ibiz.hub.getSubAppControl(ids[1] + dataRelationTag, subAppRefs[i].appId);
374
+ if (dataRelationForm) {
375
+ mergeFormDRTabpanel(dataRelationTag, dstForm, dataRelationForm);
376
+ }
377
+ }
378
+ }
379
+ }
380
+ });
381
+ }
300
382
  }
@@ -1 +1 @@
1
- {"version":3,"file":"merge-treeview.d.ts","sourceRoot":"","sources":["../../../src/utils/merge-model/merge-treeview.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI,CAiCjE"}
1
+ {"version":3,"file":"merge-treeview.d.ts","sourceRoot":"","sources":["../../../src/utils/merge-model/merge-treeview.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAiB,MAAM,kBAAkB,CAAC;AAE1D;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI,CAyDjE"}
@@ -17,10 +17,10 @@ export function mergeTreeView(dst, source) {
17
17
  }
18
18
  source.detreeNodes.forEach(sourceNode => {
19
19
  var _a;
20
- const isExist = dst.detreeNodes.find(dstNode => {
20
+ const item = dst.detreeNodes.find(dstNode => {
21
21
  return dstNode.id === sourceNode.id;
22
22
  });
23
- if (!isExist) {
23
+ if (!item) {
24
24
  (_a = dst.detreeNodes) === null || _a === void 0 ? void 0 : _a.push(sourceNode);
25
25
  }
26
26
  });
@@ -32,13 +32,149 @@ export function mergeTreeView(dst, source) {
32
32
  }
33
33
  source.detreeNodeRSs.forEach(sourceNodeRs => {
34
34
  var _a;
35
- const isExist = dst.detreeNodeRSs.find(dstNodeRs => {
35
+ // 若配置了用户标记(dynamic_overlay:before|after|replace|delete|start|end:noderesid),则需根据用户标记进行合并,否则原始数据没有则直接附加末尾
36
+ if (sourceNodeRs.userTag &&
37
+ sourceNodeRs.userTag.startsWith('dynamic_overlay') &&
38
+ sourceNodeRs.userTag.split(':').length === 3) {
39
+ mergeSubAppTreeNodeResToDst(dst, sourceNodeRs);
40
+ }
41
+ else {
42
+ const itemIndex = dst.detreeNodeRSs.findIndex(dstNodeRs => {
43
+ return (dstNodeRs.parentDETreeNodeId === sourceNodeRs.parentDETreeNodeId &&
44
+ dstNodeRs.childDETreeNodeId === sourceNodeRs.childDETreeNodeId);
45
+ });
46
+ // 若存在end标记,则需要添加到第一个end标记节点关系前面,保证end标记节点关系始终添加到最后
47
+ const endIndex = dst.detreeNodeRSs.findIndex(dstNodeRs => {
48
+ var _a;
49
+ if (dstNodeRs.parentDETreeNodeId === sourceNodeRs.parentDETreeNodeId) {
50
+ const tags = (_a = sourceNodeRs.userTag) === null || _a === void 0 ? void 0 : _a.split(':');
51
+ if (!tags || tags.length !== 3 || tags[1] !== 'end')
52
+ return false;
53
+ return true;
54
+ }
55
+ return false;
56
+ });
57
+ if (itemIndex === -1) {
58
+ if (endIndex === -1) {
59
+ (_a = dst.detreeNodeRSs) === null || _a === void 0 ? void 0 : _a.push(sourceNodeRs);
60
+ }
61
+ else {
62
+ dst.detreeNodeRSs.splice(endIndex, 0, sourceNodeRs);
63
+ }
64
+ }
65
+ }
66
+ });
67
+ }
68
+ }
69
+ /**
70
+ * 合并指定子应用树节点关系到主应用树指定位置
71
+ * @param dst 原始树
72
+ * @param sourceNode 子应用树节点关系
73
+ */
74
+ function mergeSubAppTreeNodeResToDst(dst, sourceNodeRs) {
75
+ var _a;
76
+ // dynamic_overlay:before|after|replace|delete|start|end:nodeid 定义附加位置
77
+ const [dynamicOverlay, targetPosition, targetTag] = sourceNodeRs.userTag.split(':');
78
+ if (!dynamicOverlay || !targetPosition || !targetTag)
79
+ return;
80
+ switch (targetPosition) {
81
+ case 'before':
82
+ // 在目标节点之前,dynamic_overlay:before:childnodeid,这儿最后一节拼接的是子节点标识
83
+ const beforeIndex = dst.detreeNodeRSs.findIndex(dstNode => {
84
+ return (dstNode.childDETreeNodeId === targetTag &&
85
+ dstNode.parentDETreeNodeId === sourceNodeRs.parentDETreeNodeId);
86
+ });
87
+ if (beforeIndex !== -1) {
88
+ dst.detreeNodeRSs.splice(beforeIndex, 0, sourceNodeRs);
89
+ }
90
+ break;
91
+ case 'after':
92
+ // 在目标节点之后,格式如:dynamic_overlay:after:childnodeid,最后一节拼接的是子节点标识
93
+ const afterIndex = dst.detreeNodeRSs.findIndex(dstNode => {
94
+ return (dstNode.childDETreeNodeId === targetTag &&
95
+ dstNode.parentDETreeNodeId === sourceNodeRs.parentDETreeNodeId);
96
+ });
97
+ if (afterIndex !== -1) {
98
+ dst.detreeNodeRSs.splice(afterIndex + 1, 0, sourceNodeRs);
99
+ }
100
+ break;
101
+ case 'replace':
102
+ // 替换目标节点,格式如:dynamic_overlay:replace:childnodeid,最后一节拼接的是子节点标识
103
+ const replaceIndex = dst.detreeNodeRSs.findIndex(dstNode => {
104
+ return (dstNode.childDETreeNodeId === targetTag &&
105
+ dstNode.parentDETreeNodeId === sourceNodeRs.parentDETreeNodeId);
106
+ });
107
+ if (replaceIndex !== -1) {
108
+ dst.detreeNodeRSs.splice(replaceIndex, 1, sourceNodeRs);
109
+ }
110
+ break;
111
+ case 'delete':
112
+ // 删除目标节点,格式如:dynamic_overlay:delete:childnodeid,最后一节拼接的是子节点标识
113
+ const deleteIndex = dst.detreeNodeRSs.findIndex(dstNode => {
114
+ return (dstNode.childDETreeNodeId === targetTag &&
115
+ dstNode.parentDETreeNodeId === sourceNodeRs.parentDETreeNodeId);
116
+ });
117
+ if (deleteIndex !== -1) {
118
+ dst.detreeNodeRSs.splice(deleteIndex, 1);
119
+ }
120
+ break;
121
+ case 'start':
122
+ // 在目标节点内部开始,格式如:dynamic_overlay:start:随机字符,最后一节拼接的是随机字符,读的是当前节点关系的父节点标识
123
+ const startIndex = dst.detreeNodeRSs.findIndex(dstNode => {
124
+ return dstNode.parentDETreeNodeId === sourceNodeRs.parentDETreeNodeId;
125
+ });
126
+ if (startIndex !== -1) {
127
+ dst.detreeNodeRSs.splice(startIndex, 0, sourceNodeRs);
128
+ }
129
+ break;
130
+ case 'end':
131
+ // 在目标节点内部结束,格式如:dynamic_overlay:end:随机字符,最后一节拼接的是随机字符,读的是当前节点关系的父节点标识
132
+ const endIndex = getLastIndex(dst.detreeNodeRSs, dstNode => {
133
+ return dstNode.parentDETreeNodeId === sourceNodeRs.parentDETreeNodeId;
134
+ });
135
+ if (endIndex !== -1) {
136
+ dst.detreeNodeRSs.splice(endIndex + 1, 0, sourceNodeRs);
137
+ }
138
+ break;
139
+ default:
140
+ // 未识别位置,若源树不存在该关系,则直接附加到最后
141
+ const defaultIndex = dst.detreeNodeRSs.findIndex(dstNodeRs => {
36
142
  return (dstNodeRs.parentDETreeNodeId === sourceNodeRs.parentDETreeNodeId &&
37
143
  dstNodeRs.childDETreeNodeId === sourceNodeRs.childDETreeNodeId);
38
144
  });
39
- if (!isExist) {
40
- (_a = dst.detreeNodeRSs) === null || _a === void 0 ? void 0 : _a.push(sourceNodeRs);
145
+ // 若存在end标记,则需要添加到第一个end标记节点关系前面,保证end标记节点关系始终添加到最后
146
+ const defaultEndIndex = dst.detreeNodeRSs.findIndex(dstNodeRs => {
147
+ var _a;
148
+ if (dstNodeRs.parentDETreeNodeId === sourceNodeRs.parentDETreeNodeId) {
149
+ const tags = (_a = sourceNodeRs.userTag) === null || _a === void 0 ? void 0 : _a.split(':');
150
+ if (!tags || tags.length !== 3 || tags[1] !== 'end')
151
+ return false;
152
+ return true;
153
+ }
154
+ return false;
155
+ });
156
+ if (defaultIndex === -1) {
157
+ if (defaultEndIndex === -1) {
158
+ (_a = dst.detreeNodeRSs) === null || _a === void 0 ? void 0 : _a.push(sourceNodeRs);
159
+ }
160
+ else {
161
+ dst.detreeNodeRSs.splice(defaultEndIndex, 0, sourceNodeRs);
162
+ }
41
163
  }
42
- });
164
+ break;
165
+ }
166
+ }
167
+ /**
168
+ * 获取指定数组中满足条件的最后一个元素
169
+ * @param arr 指定数组
170
+ * @param predicate 过滤条件
171
+ * @returns 找到则返回指定元素下标,反之返回-1
172
+ */
173
+ function getLastIndex(arr, predicate) {
174
+ for (let i = arr.length - 1; i >= 0; i--) {
175
+ if (predicate(arr[i])) {
176
+ return i;
177
+ }
43
178
  }
179
+ return -1;
44
180
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ibiz-template/model-helper",
3
- "version": "0.7.41-alpha.3",
3
+ "version": "0.7.41-alpha.30",
4
4
  "description": "模型辅助库",
5
5
  "main": "out/index.js",
6
6
  "types": "out/index.d.ts",
@@ -30,14 +30,14 @@
30
30
  "author": "iBiz",
31
31
  "license": "MIT",
32
32
  "dependencies": {
33
- "@ibiz-template/core": "^0.7.41-alpha.2",
34
- "@ibiz/model-core": "^0.1.76",
35
- "@ibiz/rt-model-api": "0.2.73",
33
+ "@ibiz-template/core": "^0.7.41-alpha.28",
34
+ "@ibiz/model-core": "^0.1.82",
35
+ "@ibiz/rt-model-api": "0.2.80",
36
36
  "pluralize": "^8.0.0",
37
37
  "ramda": "^0.29.1"
38
38
  },
39
39
  "devDependencies": {
40
- "@ibiz-template/runtime": "^0.7.41-alpha.3",
40
+ "@ibiz-template/runtime": "^0.7.41-alpha.30",
41
41
  "@types/pluralize": "^0.0.33",
42
42
  "@types/ramda": "^0.29.10"
43
43
  },
@@ -45,5 +45,5 @@
45
45
  "@ibiz-template/runtime": "^0.6.0",
46
46
  "ramda": "^0.29.0"
47
47
  },
48
- "gitHead": "50c9ea26dd72a8f40fea518dec9b5da2ab0a26b7"
48
+ "gitHead": "027b8b5d3efb41c540f00138b90d8389eb3f34fa"
49
49
  }