UNPKG

@ecip/ecip-web

Version:

A magical vue admin. An out-of-box UI solution for enterprise applications. Newest development stack of vue. Lots of awesome features

63 lines (58 loc) 1.65 kB
export function getDictLabel(type, value, defaultLabel) { if ((!value && value !== 0) || (!type && type !== 0)) { if (defaultLabel !== undefined) { return defaultLabel } else { return '--' } } const dictList = JSON.parse(sessionStorage.getItem('dictList') || '[]') const dicts = dictList[type] if (dicts) { for (let i = 0; i < dicts.length; i++) { if (dicts[i].value && dicts[i].value.toString() === value.toString()) { return dicts[i].label } } } if (defaultLabel !== undefined) { return defaultLabel } else { return '--' } } export function getDictValue(type, label, defaultValue) { if ((!label && label !== 0) || (!type && type !== 0)) { if (defaultValue !== undefined) { return defaultValue } else { return '--' } } const dictList = JSON.parse(sessionStorage.getItem('dictList') || '[]') const dicts = dictList[type] if (dicts) { for (let i = 0; i < dicts.length; i++) { if (dicts[i].label && dicts[i].label.toString() === label.toString()) { return dicts[i].value } } } if (defaultValue !== undefined) { return defaultValue } else { return '--' } } export function getDictList(type, filterValid) { if (!type && type !== 0) { return [] } const dictList = JSON.parse(sessionStorage.getItem('dictList') || '[]') const dicts = dictList[type] || [] if (filterValid && filterValid === true) { return dicts.filter(item => { return item.valid && (item.valid === '1' || item.valid === 1) }) } return dicts } export default { getDictLabel, getDictValue, getDictList }