fx-form-widget
Version:
109 lines (104 loc) • 3.72 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.transformSchemaToValue = exports.transformSchemaChildrenToValue = exports.transformPartitionsToSchemas = exports.transformArrayToMap = void 0;
var _objectDestructuringEmpty2 = _interopRequireDefault(require("@babel/runtime/helpers/objectDestructuringEmpty"));
var hasChildrens = ['subform', 'group'];
var hasOptions = ['subform'];
var notHasValues = ['group'];
var separators = ['separator'];
// 转换子表单或者分组或者分割线组件中children属性
var transformSchemaChildrenToValue = exports.transformSchemaChildrenToValue = function transformSchemaChildrenToValue(schemas, map) {
if (!Array.isArray(schemas)) {
return;
}
return schemas.map(function (schema) {
return transformSchemaToValue(schema, map);
}).filter(function (schema) {
(0, _objectDestructuringEmpty2["default"])(schema);
var isSystem = schema.isSystem;
return !isSystem;
});
};
// 转换schma对象
var transformSchemaToValue = exports.transformSchemaToValue = function transformSchemaToValue(schema, map) {
var _schema$viewSchema = schema.viewSchema,
viewSchema = _schema$viewSchema === void 0 ? {} : _schema$viewSchema,
widget = schema.widget,
children = schema.children,
wid = schema.wid,
fieldName = schema.fieldName,
showSerialNumberButton = schema.showSerialNumberButton,
showActionButton = schema.showActionButton,
subFormAddButtonText = schema.subFormAddButtonText,
articlePageNumber = schema.articlePageNumber,
maxCountNumber = schema.maxCountNumber,
showBulkImportButton = schema.showBulkImportButton,
exportDataButton = schema.exportDataButton;
var title = viewSchema.title,
lineType = viewSchema.lineType,
isSystem = viewSchema.isSystem;
var options = {
showSerialNumberButton: showSerialNumberButton,
showActionButton: showActionButton,
subFormAddButtonText: subFormAddButtonText,
articlePageNumber: articlePageNumber,
maxCountNumber: maxCountNumber,
showBulkImportButton: showBulkImportButton,
exportDataButton: exportDataButton,
title: title
};
var schemaData = {
wid: wid,
label: title,
widgetType: widget,
isSystem: isSystem
};
if (hasChildrens.includes(widget)) {
schemaData.children = transformSchemaChildrenToValue(children, map);
schemaData.lineStyle = lineType;
}
if (hasOptions.includes(widget)) {
schemaData.options = options;
}
if (!notHasValues.includes(widget)) {
schemaData.value = map.get(wid);
}
if (!hasChildrens.includes(widget)) {
schemaData.fieldName = fieldName;
}
if (separators.includes(widget)) {
schemaData.lineStyle = lineType;
}
;
// if (!isSystem) {
// return schemaData;
// }
return schemaData;
};
var transformPartitionsToSchemas = exports.transformPartitionsToSchemas = function transformPartitionsToSchemas(partitions, map) {
if (!Array.isArray(partitions)) {
return [];
}
return partitions.map(function (partition) {
var _partition$schemas = partition.schemas,
schemas = _partition$schemas === void 0 ? [] : _partition$schemas;
return transformSchemaToValue(schemas[0], map);
}).filter(function (schema) {
(0, _objectDestructuringEmpty2["default"])(schema);
var isSystem = schema.isSystem;
return !isSystem;
});
};
var transformArrayToMap = exports.transformArrayToMap = function transformArrayToMap(datas) {
var map = new Map();
if (!Array.isArray(datas)) {
return;
}
datas.forEach(function (data) {
var wid = data.wid,
value = data.value;
map.set(wid, value);
});
return map;
};