36 lines
929 B
JavaScript
36 lines
929 B
JavaScript
/**
|
|
* @description 获取字典
|
|
* @param {Object} dictKey
|
|
* @return 返回 name/value键值对
|
|
*/
|
|
export async function getDict(dictKey) {
|
|
const { data } = await uni.$u.http.get(`/system/dict/data/type/${ dictKey }`)
|
|
return data.map(item => ({ name: item.dictLabel, value: item.dictValue }))
|
|
}
|
|
|
|
/**
|
|
* @@description 通过字典值获取字典名
|
|
* @param {Object} value
|
|
* @param {Object} options
|
|
*/
|
|
export function getDictLabel(value, options) {
|
|
if (value && Array.isArray(options)) {
|
|
const target = options.find(item => item.value === value)
|
|
if (target) {
|
|
return target.name
|
|
}
|
|
}
|
|
return ''
|
|
}
|
|
/**
|
|
* @description 转换字典名称
|
|
* @param {Object} labelName
|
|
* @param {Object} valueName
|
|
*/
|
|
export function transDict(dict,labelName,valueName){
|
|
if(dict && labelName && valueName && Array.isArray(dict)){
|
|
return dict.map(item=>({[labelName]:item.dictLabel,[valueName]:item.dictValue}))
|
|
}
|
|
return ''
|
|
}
|