@byteluck-fe/model-driven-driven 1.3.0-beta.25 → 1.5.0-beta.10

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.
@@ -0,0 +1,429 @@
1
+ function _arrayLikeToArray(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _arrayWithHoles(arr) {
7
+ if (Array.isArray(arr)) return arr;
8
+ }
9
+ function _arrayWithoutHoles(arr) {
10
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
11
+ }
12
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
13
+ try {
14
+ var info = gen[key](arg);
15
+ var value = info.value;
16
+ } catch (error) {
17
+ reject(error);
18
+ return;
19
+ }
20
+ if (info.done) {
21
+ resolve(value);
22
+ } else {
23
+ Promise.resolve(value).then(_next, _throw);
24
+ }
25
+ }
26
+ function _asyncToGenerator(fn) {
27
+ return function() {
28
+ var self = this, args = arguments;
29
+ return new Promise(function(resolve, reject) {
30
+ var gen = fn.apply(self, args);
31
+ function _next(value) {
32
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
33
+ }
34
+ function _throw(err) {
35
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
36
+ }
37
+ _next(undefined);
38
+ });
39
+ };
40
+ }
41
+ function _instanceof(left, right) {
42
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
43
+ return !!right[Symbol.hasInstance](left);
44
+ } else {
45
+ return left instanceof right;
46
+ }
47
+ }
48
+ function _iterableToArray(iter) {
49
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
50
+ }
51
+ function _iterableToArrayLimit(arr, i) {
52
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
53
+ if (_i == null) return;
54
+ var _arr = [];
55
+ var _n = true;
56
+ var _d = false;
57
+ var _s, _e;
58
+ try {
59
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
60
+ _arr.push(_s.value);
61
+ if (i && _arr.length === i) break;
62
+ }
63
+ } catch (err) {
64
+ _d = true;
65
+ _e = err;
66
+ } finally{
67
+ try {
68
+ if (!_n && _i["return"] != null) _i["return"]();
69
+ } finally{
70
+ if (_d) throw _e;
71
+ }
72
+ }
73
+ return _arr;
74
+ }
75
+ function _nonIterableRest() {
76
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
77
+ }
78
+ function _nonIterableSpread() {
79
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
80
+ }
81
+ function _slicedToArray(arr, i) {
82
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
83
+ }
84
+ function _toConsumableArray(arr) {
85
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
86
+ }
87
+ function _unsupportedIterableToArray(o, minLen) {
88
+ if (!o) return;
89
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
90
+ var n = Object.prototype.toString.call(o).slice(8, -1);
91
+ if (n === "Object" && o.constructor) n = o.constructor.name;
92
+ if (n === "Map" || n === "Set") return Array.from(n);
93
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
94
+ }
95
+ import regeneratorRuntime from "regenerator-runtime";
96
+ import { loopFormControl } from "./designerUtils";
97
+ import { DesignerColumnControl, DesignerListControl, DesignerFormControl } from "@byteluck-fe/model-driven-core";
98
+ import { CONTROL_TYPE, FieldTypeToColumnType, isArray } from "@byteluck-fe/model-driven-shared";
99
+ import Designer from "./Designer";
100
+ import { objectDataBindControlTypes, objectDataBindKeyToFieldType } from "./constants";
101
+ export function getMasterFormControls(controls) {
102
+ var formctls = [];
103
+ // @ts-ignore
104
+ loopFormControl(controls, function(item) {
105
+ if (_instanceof(item, DesignerFormControl)) {
106
+ formctls.push(item);
107
+ } else if (item.type === CONTROL_TYPE.SUBTABLE) {}
108
+ });
109
+ return formctls;
110
+ }
111
+ /**
112
+ * @description 给modelBindInfoList中填充fieldCode和dataCode
113
+ * @description 我们生成fieldCode的规则是:DataBind的控件,取`field_${id}`,ObjectDataBind的控件,取`field_${id}_${key}`, key指的是ObjectDataBind.keys()
114
+ * */ export function fillModelBindInfoListFieldCode(modelBindInfoList) {
115
+ var dataCode = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
116
+ if (!modelBindInfoList || !Array.isArray(modelBindInfoList)) return [];
117
+ return modelBindInfoList.map(function(item) {
118
+ if (!item.dataBind) return item;
119
+ // 零代码title控件永远不填充,由后端来进行填充(title里边的dataBind绑定的是单据编号)
120
+ if (item.type === CONTROL_TYPE.TITLE) return item;
121
+ if (objectDataBindControlTypes.includes(item.type)) {
122
+ var objectDataBind = item.dataBind;
123
+ Object.keys(objectDataBind).forEach(function(key) {
124
+ var dataBind = objectDataBind[key];
125
+ // 如果是ObjectDataBind的话,需要将id拼接当前的key作为元素的fieldCode
126
+ var fieldCode = item.controlId + "_" + key;
127
+ dataBind.fieldCode = fieldCodeBeforeAddPrefix(fieldCode);
128
+ dataBind.dataCode = dataCode;
129
+ });
130
+ } else {
131
+ item.dataBind.fieldCode = fieldCodeBeforeAddPrefix(item.controlId);
132
+ item.dataBind.dataCode = dataCode;
133
+ }
134
+ return item;
135
+ });
136
+ }
137
+ function fieldCodeBeforeAddPrefix(fieldCode) {
138
+ var prefix = "field_";
139
+ if (fieldCode.startsWith(prefix)) {
140
+ return fieldCode;
141
+ }
142
+ return prefix + fieldCode;
143
+ }
144
+ /**
145
+ * @description 通过fieldType获取列表表头的type
146
+ * */ export function getColumnTypeFromFiledType(fieldType) {
147
+ return FieldTypeToColumnType[fieldType];
148
+ }
149
+ /**
150
+ * @description 通过modelBindInfoList生成多个columns
151
+ * */ export function getColumnsFromModelBindInfoList(modelBindInfoList) {
152
+ var designer = new Designer();
153
+ var columns = [];
154
+ modelBindInfoList.forEach(function(item) {
155
+ // 控件在明细子表内或者没有dataBind的话 不做生成
156
+ if (item.parentId || !item.dataBind) return;
157
+ // 如果是对象形式的dataBind的话
158
+ if (objectDataBindControlTypes.includes(item.type)) {
159
+ var objectDataBind = item.dataBind;
160
+ var datasourceBind = item.datasourceBind;
161
+ // 对象的每一个key生成一个column
162
+ Object.keys(objectDataBind).forEach(function(key) {
163
+ // 对应的dataBind
164
+ var dataBind = objectDataBind[key];
165
+ // 当前key对应的fieldType
166
+ var fieldType = objectDataBindKeyToFieldType[key].fieldType;
167
+ // 拼接当前列的caption
168
+ var caption = item.caption + "_" + objectDataBindKeyToFieldType[key].caption;
169
+ // 通过fieldType获取列类型
170
+ var controlType = getColumnTypeFromFiledType(fieldType);
171
+ if (!controlType) return;
172
+ var props = {
173
+ caption: caption,
174
+ dataBind: dataBind
175
+ };
176
+ if (key === "currency") {
177
+ props.optionConfig = "datasource";
178
+ props.datasourceBind = datasourceBind;
179
+ }
180
+ // @ts-ignore
181
+ var column = designer.createControlInstance(controlType, {
182
+ props: props
183
+ });
184
+ column && columns.push(column);
185
+ });
186
+ } else {
187
+ var controlType = getColumnTypeFromFiledType(item.fieldType);
188
+ if (!controlType) return;
189
+ // @ts-ignore
190
+ var column = designer.createControlInstance(controlType, {
191
+ props: {
192
+ caption: item.caption,
193
+ dataBind: item.dataBind,
194
+ datasourceBind: item.datasourceBind
195
+ }
196
+ });
197
+ column && columns.push(column);
198
+ }
199
+ });
200
+ return columns;
201
+ }
202
+ export function getColumnsFromFiledType(fieldTypes) {
203
+ var designer = new Designer();
204
+ var fieldTypesMap = Array.isArray(fieldTypes) ? fieldTypes : [
205
+ fieldTypes
206
+ ];
207
+ var result = fieldTypesMap.map(function(fieldType) {
208
+ var columnType = getColumnTypeFromFiledType(fieldType);
209
+ return designer.createControlInstance(columnType);
210
+ });
211
+ return Array.isArray(fieldTypes) ? result : result[0];
212
+ }
213
+ function toSchema(schema) {
214
+ if (Array.isArray(schema)) {
215
+ return schema.map(function(item) {
216
+ return item.toSchema();
217
+ });
218
+ } else {
219
+ return schema.toSchema();
220
+ }
221
+ }
222
+ function getModelBindInfoList(controls) {
223
+ if (Array.isArray(controls)) {
224
+ return controls.map(function(control) {
225
+ return control.toDataBindModel();
226
+ }).filter(function(item) {
227
+ return !!item;
228
+ }).flat();
229
+ }
230
+ return controls.toDataBindModel();
231
+ }
232
+ function checkSchema(controls, messages, ignore) {
233
+ return _checkSchema.apply(this, arguments);
234
+ }
235
+ function _checkSchema() {
236
+ _checkSchema = _asyncToGenerator(/*#__PURE__*/ regeneratorRuntime.mark(function _callee(controls, messages, ignore) {
237
+ var result;
238
+ return regeneratorRuntime.wrap(function _callee$(_ctx) {
239
+ while(1)switch(_ctx.prev = _ctx.next){
240
+ case 0:
241
+ if (!Array.isArray(controls)) {
242
+ _ctx.next = 5;
243
+ break;
244
+ }
245
+ _ctx.next = 3;
246
+ return Promise.all(controls.map(function(control) {
247
+ return control.validate(messages, ignore);
248
+ }));
249
+ case 3:
250
+ result = _ctx.sent;
251
+ return _ctx.abrupt("return", result.every(function(state) {
252
+ return state;
253
+ }));
254
+ case 5:
255
+ _ctx.next = 7;
256
+ return controls.validate(messages, ignore);
257
+ case 7:
258
+ return _ctx.abrupt("return", _ctx.sent);
259
+ case 8:
260
+ case "end":
261
+ return _ctx.stop();
262
+ }
263
+ }, _callee);
264
+ }));
265
+ return _checkSchema.apply(this, arguments);
266
+ }
267
+ // 不可以被权限控制的控件
268
+ var PermissionExcludeControlTypes = [
269
+ CONTROL_TYPE.TITLE,
270
+ CONTROL_TYPE.GRID_TABLE_COLUMN,
271
+ CONTROL_TYPE.SUBTABLE_COLUMN,
272
+ CONTROL_TYPE.OPERATION_COLUMN,
273
+ CONTROL_TYPE.DATA_VIEW,
274
+ CONTROL_TYPE.LIST_VIEW,
275
+ CONTROL_TYPE.HEADER,
276
+ CONTROL_TYPE.FOOTER,
277
+ CONTROL_TYPE.SIMPLE_SEARCH,
278
+ CONTROL_TYPE.ROW,
279
+ CONTROL_TYPE.GRID_ROW,
280
+ CONTROL_TYPE.COL,
281
+ CONTROL_TYPE.GRID,
282
+ CONTROL_TYPE.DIVIDER,
283
+ // 暂时不能控制权限
284
+ CONTROL_TYPE.TAB_PANE,
285
+ CONTROL_TYPE.TAB,
286
+ CONTROL_TYPE.CARD_GROUP,
287
+ ];
288
+ // 不可以编辑的控件
289
+ var cannotEditControlTypes = [
290
+ CONTROL_TYPE.CALC
291
+ ];
292
+ // 列表操作列单独处理三个按钮的权限
293
+ var LIST_OPERATION_BUTTON_PERMISSIONS_MAPS = {
294
+ check: {
295
+ id: "listPageCheckBtnId",
296
+ caption: "查看"
297
+ },
298
+ edit: {
299
+ id: "listPageEditBtnId",
300
+ caption: "编辑"
301
+ },
302
+ delete: {
303
+ id: "listPageDeleteBtnId",
304
+ caption: "删除"
305
+ }
306
+ };
307
+ // 生成权限字段
308
+ function generatePermissions(controls, parent) {
309
+ var result = [];
310
+ if (isArray(controls)) {
311
+ var _result;
312
+ (_result = result).push.apply(_result, _toConsumableArray(controls.map(function(item) {
313
+ return generatePermissions(item, parent);
314
+ }).flat()));
315
+ } else {
316
+ var type = controls.type;
317
+ var _props = controls.props, caption = _props.caption, content = _props.content;
318
+ var permissionItem;
319
+ if (!PermissionExcludeControlTypes.includes(type)) {
320
+ var ref;
321
+ permissionItem = {
322
+ controlId: controls.id,
323
+ caption: caption || content || controls.name,
324
+ type: controls.type,
325
+ controlType: controls.controlType,
326
+ parentId: (ref = parent === null || parent === void 0 ? void 0 : parent.controlId) !== null && ref !== void 0 ? ref : null,
327
+ canEdit: !cannotEditControlTypes.includes(type),
328
+ canRead: true,
329
+ canHide: true,
330
+ group: "element"
331
+ };
332
+ if (parent && parent.type === CONTROL_TYPE.SUBTABLE) {
333
+ // 如果有parent,则利用下划线拼接caption
334
+ permissionItem.caption = parent.caption + "_" + permissionItem.caption;
335
+ }
336
+ if (type === CONTROL_TYPE.VUE_FORM_ITEM) {
337
+ permissionItem.caption = controls.props.controlExportName || controls.name;
338
+ }
339
+ if (_instanceof(controls, DesignerFormControl) || _instanceof(controls, DesignerColumnControl)) {
340
+ var ref1, ref2, ref3, ref4;
341
+ if (((ref1 = controls.props) === null || ref1 === void 0 ? void 0 : (ref2 = ref1.dataBind) === null || ref2 === void 0 ? void 0 : ref2.fieldCode) !== undefined && ((ref3 = controls.props) === null || ref3 === void 0 ? void 0 : (ref4 = ref3.dataBind) === null || ref4 === void 0 ? void 0 : ref4.fieldCode) !== "") {
342
+ permissionItem.group = "field";
343
+ }
344
+ }
345
+ result.push(permissionItem);
346
+ //追加vue容器权限
347
+ if (type === CONTROL_TYPE.VUE_FORM_ITEM) {
348
+ var ref5, ref6, ref7, ref8;
349
+ var vueFormItemGroup = "element";
350
+ if (((ref5 = controls.props) === null || ref5 === void 0 ? void 0 : (ref6 = ref5.dataBind) === null || ref6 === void 0 ? void 0 : ref6.fieldCode) !== undefined && ((ref7 = controls.props) === null || ref7 === void 0 ? void 0 : (ref8 = ref7.dataBind) === null || ref8 === void 0 ? void 0 : ref8.fieldCode) !== "") {
351
+ vueFormItemGroup = "field";
352
+ }
353
+ var permissions = controls.props["permissions"];
354
+ permissions === null || permissions === void 0 ? void 0 : permissions.map(function(item) {
355
+ var _id;
356
+ permissionItem = {
357
+ controlId: item.key,
358
+ caption: item.caption,
359
+ type: controls.type,
360
+ controlType: controls.controlType,
361
+ parentId: (_id = controls.id) !== null && _id !== void 0 ? _id : null,
362
+ canEdit: true,
363
+ canRead: true,
364
+ canHide: true,
365
+ group: vueFormItemGroup
366
+ };
367
+ result.push(permissionItem);
368
+ });
369
+ }
370
+ } else if (type === CONTROL_TYPE.OPERATION_COLUMN) {
371
+ // 列表的操作列单独处理
372
+ Object.entries(LIST_OPERATION_BUTTON_PERMISSIONS_MAPS).reduce(function(result, param) {
373
+ var _param = _slicedToArray(param, 2), key = _param[0], ref = _param[1], caption = ref.caption, controlId = ref.id;
374
+ var operationItem = controls.props[key];
375
+ if (operationItem && operationItem.isShow) {
376
+ var ref1;
377
+ // 只能控制是否显示
378
+ result.push({
379
+ controlId: controlId,
380
+ caption: caption,
381
+ type: controls.type,
382
+ controlType: controls.controlType,
383
+ parentId: (ref1 = parent === null || parent === void 0 ? void 0 : parent.controlId) !== null && ref1 !== void 0 ? ref1 : null,
384
+ canEdit: false,
385
+ canRead: false,
386
+ canHide: true,
387
+ group: "element"
388
+ });
389
+ }
390
+ return result;
391
+ }, result);
392
+ }
393
+ // else if (type === CONTROL_TYPE.CUSTOM_COLUMN) {
394
+ // //追加自定义列上的vue容器权限
395
+ // ;(controls as any)?.children?.map((vueControl: any) => {
396
+ // if (vueControl.type === CONTROL_TYPE.VUE_FORM_ITEM) {
397
+ // const { caption, content } = vueControl.props as any
398
+ // permissionItem = {
399
+ // controlId: vueControl.id,
400
+ // caption: caption ?? content ?? vueControl.name,
401
+ // type: vueControl.type,
402
+ // controlType: vueControl.controlType,
403
+ // parentId: null,
404
+ // canEdit: true,
405
+ // canRead: true,
406
+ // canHide: true,
407
+ // group: 'element',
408
+ // }
409
+ // result.push(permissionItem)
410
+ // }
411
+ // })
412
+ // }
413
+ if (controls.children) {
414
+ var _result1;
415
+ (_result1 = result).push.apply(_result1, _toConsumableArray(controls.children.map(function(item) {
416
+ return generatePermissions(item, parent);
417
+ }).flat()));
418
+ }
419
+ if (_instanceof(controls, DesignerListControl)) {
420
+ var // 明细子表和列表的需要给parentId
421
+ _result2;
422
+ (_result2 = result).push.apply(_result2, _toConsumableArray(controls.props.headers.map(function(item) {
423
+ return generatePermissions(item, permissionItem);
424
+ }).flat()));
425
+ }
426
+ }
427
+ return result;
428
+ }
429
+ export { toSchema, getModelBindInfoList, checkSchema, generatePermissions };