Files
yidaima/RuoYi-Vue/tmp-logs/qing-ui-preview/src/utils/dict.js

32 lines
748 B
JavaScript
Raw Normal View History

const dictData = {}
const emptyDict = []
function normalizeOptions(options) {
if (!Array.isArray(options)) {
return emptyDict
}
return options.map((option) => {
const label = option.label || option.name || option.value
const value = option.value || label
return {
...option,
label,
name: option.name || label,
value
}
})
}
export default {
getDictDataByType(type) {
return normalizeOptions(dictData[type])
},
getDictLabel(type, value) {
if (value === undefined || value === null || value === "") {
return "-"
}
const matched = normalizeOptions(dictData[type]).find((option) => String(option.value) === String(value))
return matched ? matched.label : value
}
}