 定义的dacaData类 /** * @classdesc 字典数据 * @property {String} label 标签 * @property {*} value 标签 * @property {Object} raw 原始数据 */ export default class DictData { constructor(label, value, raw) { this.label = label this.value = value this.raw = raw } } 字典 /** * 加载字典 * @param {Dict} dict 字典 * @param {DictMeta} dictMeta 字典元数据 * @returns {Promise} */ function loadDict(dict, dictMeta) { return dictMeta.request(dictMeta).then((response) => { const type = dictMeta.type; let dicts = dictMeta.responseConverter(response, dictMeta); if (!(dicts instanceof Array)) { console.error("the return of responseConverter must be Array."); dicts = []; } else if ( dicts.filter((d) => d instanceof DictData).length !== dicts.length ) { console.error("the type of elements in dicts must be DictData"); dicts = []; } dict.type[type].splice(0, Number.MAX_SAFE_INTEGER, ...dicts); dicts.forEach((d) => { Vue.set(dict.label[type], d.value, d.label); }); return dicts; }); }