erp-el-element/dict/DictConverter.js

20 lines
739 B
JavaScript

import DictOptions from './DictOptions'
import DictData from './DictData'
export default function(dict, dictMeta) {
// console.log(dict,"dict", dictMeta,"dictMeta");
const label = determineDictField(dict, dictMeta.labelField, ...DictOptions.DEFAULT_LABEL_FIELDS)
const value = determineDictField(dict, dictMeta.valueField, ...DictOptions.DEFAULT_VALUE_FIELDS)
const type = determineDictField(dict, dictMeta.typeField, ...DictOptions.DEFAULT_TYPE_FIELDS)
return new DictData(dict[label], dict[value], dict,dict[type])
}
/**
* 确定字典字段
* @param {DictData} dict
* @param {...String} fields
*/
function determineDictField(dict, ...fields) {
return fields.find(f => Object.prototype.hasOwnProperty.call(dict, f))
}