import dictData from './dictData.json'; /** * @param {*} keys * @returns * 处理本地文件字典 对应查找 * 使用方法可定义全局变量 简化简化代码工程 * [this.departments, this.materials]= getSelectData(['departments', 'materials']); */ export function getSelectData(keys) { const dict = dictData || {}; if (!keys && keys !== '') return null; //处理单个字典值 if (typeof keys === 'string') { return dict[keys] || null; } //处理多个本地字典值 if (Array.isArray(keys)) { return keys.map(k => dict[k] || null); } if (typeof keys === 'object') { const result = {}; for (const [key, value] of Object.entries(keys)) { const list = dict[key]; if (!Array.isArray(list)) { result[key] = null; continue; } if (typeof value === 'undefined') { result[key] = list; } else if (Array.isArray(value)) { result[key] = value.map(v => list.find(item => String(item.value) === String(v)) || null); } else { result[key] = list.find(item => String(item.value) === String(value)) || null; } } return result; } return null; }