kdesign-ui
Version:
kd is from company of klx, it provide quickly genarator company inner business front structure
67 lines (66 loc) • 1.98 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GenParams = exports.fieldMapType = exports.fieldType = void 0;
exports.fieldType = {
0: 'String',
1: 'Number',
5: 'Number',
2: 'Boolean',
4: 'Object',
6: 'Array',
7: 'Array',
8: 'Array',
9: 'Array',
10: 'Date',
11: 'File'
};
exports.fieldMapType = {
0: 'String',
1: 'Number',
2: 'Boolean',
3: 'Array',
4: 'Object',
5: 'Number',
6: 'Array',
7: 'Array',
8: 'Array',
9: 'Array',
10: 'Date',
11: 'String'
};
var GenParams = /** @class */ (function () {
function GenParams() {
this.typeMap = exports.fieldMapType;
this.result = {};
}
GenParams.prototype.gen = function (data, prefix, isArray) {
if (prefix === void 0) { prefix = ''; }
if (isArray === void 0) { isArray = false; }
this.result = {};
genHandler.call(this, data, prefix, isArray);
function genHandler(data, prefix, isArray) {
var _this = this;
if (prefix === void 0) { prefix = ''; }
if (isArray === void 0) { isArray = false; }
data.forEach(function (d) {
var fullKey = "" + (isArray ? prefix + (d.name || '') + '[0]' : prefix + (d.name || ''));
_this.result[fullKey] = _this.getRes(d);
if (d.data && d.data.length) {
genHandler.call(_this, d.data, isArray ? fullKey + "." : fullKey, _this.typeMap[d.type] === 'Array');
}
});
}
return this.result;
};
GenParams.prototype.getRes = function (d) {
if (d.must) {
return {
type: this.typeMap[d.type],
required: true
};
}
return this.typeMap[d.type];
};
return GenParams;
}());
exports.GenParams = GenParams;